logger = logging.getLogger("test")
logger.setLevel(logging.DEBUG)
formatter = logging.Formatter(
"[%(name)s][PID:%(process)d][%(threadName)s:%(thread)d][%(levelname)s][%(asctime)s][%(message)s]",
"%Y-%m-%d %H:%M:%S")
f_handler = logging.FileHandler("mylog.txt", encoding="utf-8")
f_handler.setLevel(logging.INFO)
f_handler.setFormatter(formatter)
s_handler = logging.StreamHandler()
s_handler.setLevel(logging.DEBUG)
s_handler.setFormatter(formatter)
logger.addHandler(f_handler)
logger.addHandler(s_handler)
logger.debug("Debug Message")
logger.info("Info Message")
logger.warning("Warning Message")
logger.error("Error Message")
[loggers]
keys=root,test
[handlers]
keys=fileHandler,streamHandler
[formatters]
keys=fmt
[logger_root]
level=DEBUG
handlers=streamHandler
[logger_test]
level=DEBUG
handlers=fileHandler
qualname=test
[handler_streamHandler]
class=StreamHandler
level=DEBUG
formatter=fmt
args=(sys.stdout,)
[handler_fileHandler]
class=FileHandler
level=INFO
formatter=fmt
args=('mylog1.txt','a',"utf-8")
[formatter_fmt]
format=%(asctime)s - %(name)s - %(levelname)s - %(message)s
datefmt=