python – 哪个模块应该包含logging.config.dictConfig(my_dictionary)? my_dictionary怎么样?
作者:互联网
这都是Python.我仍在学习…
我为我的Python应用程序编写了两个模块:Module1和Module2.
我需要将我的日志记录结果发送到三个不同的文件. Module1发送到setup.log和setupdetails.log文件,Module2发送到runall.log
Module2是我运行的应用程序.在其中是一个调用Module1的import语句.
因为我已经在my_dictionary中配置了我的日志记录,其中一个模块应该包含字典?哪个模块应该包含logging.config.dictConfig(my_dictionary)函数?
你知道在哪里我能找到一个好的脚本以及如何使用dictConfig的例子吗?
解决方法:
所以,我终于明白了.
如果将字典放在子模块Module 1中(并设置Propagate:True),这一切都很有效.
MY_DICTIONARY = {
'version': 1,
'disable_existing_loggers': False,
'formatters': {
'verbose': {
'format': '%(levelname)-8s %(asctime)s %(module)s %(process)d %(thread)d %(message)s',
'datefmt': '%a, %d %b %Y %H:%M:%S'
},
'standard': {
'format': '%(asctime)s [%(levelname)s] %(name)s: %(message)s',
'datefmt': '%a, %d %b %Y %H:%M:%S'
},
'simple': {
'format': '%(asctime)s %(levelname)-8s %(message)s',
'datefmt': '%a, %d %b %Y %H:%M:%S'
}
#etc.
}
}
接下来是以下电话:
logging.config.dictConfig(MY_DICTIONARY)
vmrunalllogger = logging.getLogger('VMRunAll_Python_Logger')
然后在第2单元(父模块)中,有:
logging.config.dictConfig(MY_DICTIONARY)
mylogger = logging.getLogger('RunAll_Logger')
我找不到具体的例子,显示两个不同的模块记录到我正在做的多个文件,但来自多个来源的信息如下有帮助:
> From the Python documentation
> Another question on Stackoverflow.com
> And the examples of in the cookbook
标签:multiple-files,python,logging,dictionary,module 来源: https://codeday.me/bug/20190825/1720449.html