当我像这样运行扭曲的应用程序时:
twistd --pidfile ./twistd.pid -l $HOME/logs/my_application.log -oy service.tac
我发现它不记录通过python日志记录系统发送的任何内容。我注意到在twisted中有一个“ PythonLoggingObserver”,但是它将twisted日志重定向到日志记录模块。
我想弄清楚如何使所有日志(无论日志模块如何)都转到扭曲的“ -l”命令指定的日志文件中。我怀疑我的日志已写入守护程序的标准输出中。
这是我初始化.tac文件中的python日志的方法:
import logging
LOG_LEVEL = logging.DEBUG
logger = logging.getLogger(module_name)
logger.setLevel(LOG_LEVEL)
logging.basicConfig(level=LOG_LEVEL)
使用添加流处理程序twisted.python.log.logfile
。例如:
>>> from sys import stdout
>>> from logging import StreamHandler, getLogger
>>> from twisted.python.log import startLogging, logfile
>>> observer = startLogging(stdout, setStdout=False)
2015-05-02 06:34:39-0400 [-] Log opened.
>>> getLogger().addHandler(StreamHandler(stream=logfile))
>>> getLogger().log(100, "Hello")
2015-05-02 06:36:26-0400 [-] Hello
>>>
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句