A .py script uses logging to output two log files at the same time.

problem description

A .py script uses logging to output two log files at the same time.
through two different configuration files, two log files can be generated.
but only the latter log object can be written to the content, and the previous log object cannot write to the content

.

the environmental background of the problems and what methods you have tried

for some unknown reason, it is suspected that it has something to do with the handlers type?

related codes

/ / Please paste the code text below (please do not replace the code with a picture)
test.py
-sharphammer bind Env python
-sharp coding: utf-8
import logging.config
import logging
def get_logger (logger_name, logger_path):

logging.config.fileConfig(logger_path)
return logging.getLogger(logger_name)

if name ="_ _ main__":

log_path1="logging.conf"
log_path2="audit.conf"

logger1 = get_logger("Glon", log_path1)
logger2 = get_logger("GlonHo", log_path2)

logger1.info(" test1 log msg: %s", "111111111111111111111")
logger2.info(" test2 log msg: %s", "222222222222222222222")

logging.conf
[loggers]
keys=root

[handlers]
keys=rotatingHandler

[formatters]
keys=simpleFormatter

[logger_root]
level=INFO
handlers=rotatingHandler

[handler_rotatingHandler]
class=logging.handlers.TimedRotatingFileHandler
level=INFO
formatter=simpleFormatter
args= ("trace.log"," midnight")

[formatter_simpleFormatter]
format=% (asctime) s% (levelname) s% (message) s
datefmt=

audit.conf
[loggers]
keys=root

[handlers]
keys=rotatingHandler

[formatters]
keys=simpleFormatter

[logger_root]
level=INFO
handlers=rotatingHandler

[handler_rotatingHandler]
class=logging.handlers.TimedRotatingFileHandler
level=INFO
formatter=simpleFormatter
args= ("wacaudit_console0.csv"," midnight")

[formatter_simpleFormatter]
format=% (message) s

what result do you expect? What is the error message actually seen?

topic description

expectation: log information is written into trace.log and wacaudit_console0.csv log files at the same time
actually: these two log files can be generated at the same time, but log information is only written into wacaudit_console0.csv, but not into trace.log
result:
cat trace.log
cat wacaudit_console0.csv
test2 log msg: 22222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222222

the environmental background of the problems and what methods you have tried

swap the two lines of code
logger1 = get_logger ("Glon", log_path1)
logger2 = get_logger (" GlonHo", log_path2)
in test.py, and the log information can be written into trace.log,wacaudit_console0.csv, so there is no value to write in.

Mar.31,2021

change the configuration and add a variable disable_existing_loggers

  

to output two log from one script file, it is recommended to integrate the above logging.conf and audit.conf into one configuration file

Menu