我有文件“a.py”,其中寫入了日志記錄配置。另一個文件“b.py”,我只在其中導入日志記錄并寫入日志,它創建空文件但無法寫入內容。這是來自兩個文件的代碼。請告訴我我在哪里遺漏了什么。謝謝“a.py”import logging.configLOGGING = { 'version': 1, 'disable_existing_loggers': False, 'formatters': { 'default': { 'format': '%(asctime)s %(pathname)s:%(lineno)d %(message)s', }, }, 'handlers': { 'default': { 'level': 'DEBUG', 'class': 'logging.handlers.RotatingFileHandler', 'filename': 'rror.log', 'backupCount': 2, 'formatter': 'default', }, 'information': { 'level': 'INFO', 'class': 'logging.handlers.RotatingFileHandler', 'filename': 'information.log', 'backupCount': 2, 'formatter': 'default', }, }, 'loggers': { 'logger1': { 'handlers': ['default'], 'level': 'DEBUG', 'propagate': False, }, 'logger2': { 'handlers': ['information'], 'level': 'INFO', 'propagate': False, }, },}logging.config.dictConfig(LOGGING)“b.py”import logginglogging.getLogger('logger1').info("hey there!")logging.getLogger('logger2').debug("hey logger2")
1 回答

喵喵時光機
TA貢獻1846條經驗 獲得超7個贊
將“b.py”更改為:
from a import logging
logging.getLogger('logger1').debug("hey there!")
logging.getLogger('logger2').info("hey logger2")
添加回答
舉報
0/150
提交
取消