亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

模塊化日志記錄不會寫入文件 - Python

模塊化日志記錄不會寫入文件 - Python

弒天下 2022-12-20 14:18:10
我有文件“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")


查看完整回答
反對 回復 2022-12-20
  • 1 回答
  • 0 關注
  • 97 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號