Python标准记录器而不是扭曲记录器

时间:2016-08-05 11:35:20

标签: python-2.7 logging twisted twistd

我试图守护一个使用Python2.7标准库记录器的简单Twisted应用程序。

以下是设置:

Python应用程序文件(run.py):

import logging
import logging.config
from twisted.internet import reactor

import conf

def main():
    logging.config.dictConfig(conf.LOGGERCONF)
    logger = logging.getLogger(conf.LOGGERNAME)
    logger.debug('Starting the reactor...')
    reactor.callWhenRunning(lambda: logger.info('Reactor started'))
    reactor.run()

main()

Twistd应用程序文件(daemon.tac):

from twisted.application.service import Application
from twisted.python.log import PythonLoggingObserver
from twisted.python.log import ILogObserver

application = Application('run')
application.setComponent(ILogObserver, PythonLoggingObserver().emit)

日志观察文件(daemonlog.py):

from twisted.python import log

def logger():
    return log.PythonLoggingObserver().emit

使用以下命令启动应用程序:

python run.py

一切正常,日志消息被正确归档和显示(根据记录器配置)。

尝试使用以下命令进行守护:

twistd -y daemon.tac --logger=daemonlog.logger

守护程序启动正常,我可以看到创建的twistd.pid文件(使用正确的pid编号),在ps -ef命令结果中运行的守护程序,但我看不到任何日志文件(都没有扭曲应用程序正常启动时没有扭曲的.log或日志文件。

最后,我想只使用Python的标准库记录器和"旁路"扭曲的记录器。

我可能会遗漏某些内容或误入歧途,我们将不胜感激。

0 个答案:

没有答案