Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/logging/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 2.7 Python2.7 RotatingFileHandler不从模块进行日志记录_Python 2.7_Logging - Fatal编程技术网

Python 2.7 Python2.7 RotatingFileHandler不从模块进行日志记录

Python 2.7 Python2.7 RotatingFileHandler不从模块进行日志记录,python-2.7,logging,Python 2.7,Logging,我试图在Python2.7中使用模块日志设置RotatingFileHandler,但无论我做什么,我只能获得顶层脚本来写入日志文件 以下是我的顶级脚本中的代码: import logging import Lib.download as d LOG_FILE = public_dir + "\script2.log" log = logging.getLogger('Script_2') log.setLevel(logging.DEBUG) rotate_handler = handl

我试图在Python2.7中使用模块日志设置RotatingFileHandler,但无论我做什么,我只能获得顶层脚本来写入日志文件

以下是我的顶级脚本中的代码:

import logging
import Lib.download as d

LOG_FILE = public_dir + "\script2.log"

log = logging.getLogger('Script_2')
log.setLevel(logging.DEBUG)

rotate_handler = handlers.RotatingFileHandler(LOG_FILE, maxBytes = 5000, backupCount=5)
log_format = logging.Formatter('%(asctime)s %(name)-8s:%(levelname)s:%(message)s')
rotate_handler.setFormatter(log_format)

log.addHandler(rotate_handler)

log.debug('Launching meat of script_2')
d.some_function()
log.info('script_2 completed successfully')
“下载”模块中的代码:

import logging
log = logging.getLogger('script_2.download')

def some_function():
    log.debug('doing some_function')
我的输出不反映模块日志记录

2014-01-13 12:56:04,428 Script_2:DEBUG:Launching the meat of script_2
2014-01-13 12:56:05,005 Script_2:INFO:Script_2 completed successfully
我错过了什么?日志模块工作得很好,直到我添加了RotatingFileHandler

我尝试过论坛上的其他解决方案,包括


但是没有骰子。有什么帮助吗?

不确定您是否找到了答案,但根据提供的信息,您似乎与记录器的名称不匹配

在主脚本中,您将记录器定义为
'script\u 2'
,在
'download'
模块中,您引用的是
'script\u 2.download'
。因此,父项是大写的,子项不是

因此,实际上有两个不同的记录器不共享相同的层次结构