
我在一个项目使用一个 logging_config.py 对 logging 做了配置,如何在其他模块中使用这个配置?
比如说配置是这样的。
import logging import logging.config logger = logging.getLogger(__name__) # load config from file # logging.config.fileConfig('logging.ini', disable_existing_loggers=False) # or, for dictConfig logging.config.dictConfig({ 'version': 1, 'disable_existing_loggers': False, # this fixes the problem 'formatters': { 'standard': { 'format': '%(asctime)s [%(levelname)s] %(name)s: %(message)s' }, }, 'handlers': { 'default': { 'level':'INFO', 'class':'logging.StreamHandler', }, }, 'loggers': { '': { 'handlers': ['default'], 'level': 'INFO', 'propagate': True } } }) 那在其他模块使用这个配置之前,不是要先运行一个这个模块的代码吗?如果每个模块(程序不只有一个入口)都要 import logging_cofig,那不是就 import but not used 了 we