0
我在__init__.py
下面的代码,建立了我的记录我的Python包:为什么不记录设置工作?
import logging
import logging.config
global LOG_FILENAME
LOG_CONFIG_FILE=os.path.join(os.path.dirname(os.path.abspath(__file__)),
'logging_config.conf')
if os.path.isfile(LOG_CONFIG_FILE)!=True:
raise Exception
logging.config.fileConfig(LOG_CONFIG_FILE,disable_existing_loggers=False)
LOG=logging.getLogger('root')
LOG.info('Initializing PyCoTools')
LOG.info('Initializing Logging System')
LOG.info('logging config file at: {}'.format(LOG_CONFIG_FILE))
在同一目录__init__.py
我有一个日志配置文件名为logging_config.conf
,内容如下:
[formatters]
keys: simple,custom,custom2
[handlers]
keys: console,fh,rotatingfh
[loggers]
keys: root,pycopi,PEAnalysis,pydentify2
[logger_root]
level: DEBUG
handlers: rotatingfh,console
qualname=root
propagate=0
[logger_pycopi]
level: DEBUG
handlers: rotatingfh,console
qualname=pycopi
propagate=0
[logger_PEAnalysis]
level: DEBUG
handlers: rotatingfh,console
qualname=PEAnalysis
propagate=0
[logger_pydentify2]
level: DEBUG
handlers: rotatingfh,console
qualname=pydentify2
propagate=0
[handler_console]
class: logging.StreamHandler
args: (sys.stdout,)
formatter: custom2
level: DEBUG
[handler_fh]
class: logging.FileHandler
args: ('log.log','a')
formatter: custom2
level=DEBUG
[handler_rotatingfh]
class: logging.handlers.RotatingFileHandler
args: ('log.log',100000,2)
formatter: custom2
level=DEBUG
[formatter_simple]
format: %(name)s:%(levelname)s: %(message)s
[formatter_custom]
format: %(asctime)s:%(levelname)s:%(filename)s:%(funcName)s:%(message)s
[formatter_custom2]
format: %(levelname)s:%(name)s:%(module)s:%(lineno)d:%(message)s
然后,每蟒模块中(如pycopi.py
)我有:
LOG=logging.getLogger(__name__)
所以我可以像每个文件开始记录:
LOG.debug('Debugging my code')
这是按预期工作(即在今天早些时候登录到控制台和级别调试文件),但没有明确地改变任何东西,这个记录器不再实际上做任何日志记录。任何人都可以发现问题吗?