![](/img/trans.png)
[英]How may i find the key in my_dictionary , with dictionaries, and i don`t know exactly how many dictionaries i will have in my_dictionary?
[英]Which module should contain logging.config.dictConfig(my_dictionary)? What about 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')
我找不到具體的例子,顯示兩個不同的模塊記錄到我正在做的多個文件,但來自多個來源的信息如下有幫助:
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.