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 Tornado:文件日志也会写入标准输出_Python 2.7_Logging_Tornado - Fatal编程技术网

Python 2.7 Tornado:文件日志也会写入标准输出

Python 2.7 Tornado:文件日志也会写入标准输出,python-2.7,logging,tornado,Python 2.7,Logging,Tornado,我使用FileHandler将tornado访问日志写入文件,但相同的日志会输出到标准输出 from tornado.options import define, options options.logging = None options.parse_command_line() access_log = logging.getLogger('tornado.access') access_log.setLevel(logging.INFO) handler = logging.FileH

我使用FileHandler将tornado访问日志写入文件,但相同的日志会输出到标准输出

from tornado.options import define, options

options.logging = None
options.parse_command_line()

access_log = logging.getLogger('tornado.access')
access_log.setLevel(logging.INFO)
handler = logging.FileHandler(log_path)
access_log.addHandler(handler)

// stdout::
INFO:tornado.access:200 GET / (ip) 0.93ms

它确实会写入日志文件,但我不知道为什么它也会输出到stdout。

Python的日志框架基于记录器的层次结构。默认情况下,记录到tornado.access的内容也会传播到根记录器(默认情况下,根记录器会转到stderr)。如果不希望访问日志重复,请设置以下属性:

from tornado.options import define, options

options.logging = None
options.parse_command_line()

access_log = logging.getLogger('tornado.access')
access_log.setLevel(logging.INFO)
handler = logging.FileHandler(log_path)
access_log.addHandler(handler)

// stdout::
INFO:tornado.access:200 GET / (ip) 0.93ms
access_log.propagate = False