How to add parameters to the output format of the logging module?

logging.basicConfig(level=logging.INFO
                    filename="new.log",
                    filemode="a",
                    format="%(asctime)s - %(levelname)s: %(message)s"
                    )

now I want to add a custom variable to format, such as appname,

look up the usage of logging.info on the Internet, as follows:
logging.info (msg, args, * kwargs)

then I modify format="% (asctime) s -% (levelname) s:% (appname) s% (message) s"), add a% (appname) s,
, and then run logging.info (msg, appname="xxx") with an error.

how can I implement the above requirements?

Dec.16,2021

import logging
import sys

def my_get_logger(appname):
    -sharploggerroot logger
    logger=logging.getLogger(appname)
    -sharp
    formatter=logging.Formatter('%(asctime)s    %(levelname)s   %(appname)s:  %(message)s')

    -sharp
    file_handler=logging.FileHandler('test.log')
    -sharp 
    file_handler.setFormatter(formatter)

    -sharp
    console_handler=logging.StreamHandler(sys.stdout)
    console_handler.formatter=formatter

    -sharplogger
    logger.addHandler(file_handler)
    logger.addHandler(console_handler)

    -sharpwarn
    logger.setLevel(logging.INFO)
    return logger

if __name__ == '__main__':
    logger=my_get_logger('mark')
    logger.debug('this is debug info',extra={'appname':''})
    logger.info('this is information',extra={'appname':''})
    logger.warning('this is warning message',extra={'appname':''})
    logger.error('this is error message',extra={'appname':''})
    logger.fatal('this is fatal message,it is same ad logger.critical',extra={'appname':''})
    logger.critical('this is critical message',extra={'appname':''})

run result:

2018-11-27 09:42:55,118    INFO   :  this is information
2018-11-27 09:42:55,120    WARNING   :  this is warning message
2018-11-27 09:42:55,120    ERROR   :  this is error message
2018-11-27 09:42:55,120    CRITICAL   :  this is fatal message,it is same ad logger.critical
2018-11-27 09:42:55,120    CRITICAL   :  this is critical message

reference article: Python module analysis: section 4-logging log module

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1ea4f4b-1d19.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1ea4f4b-1d19.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?