Logging to a file using twistd and python logging

When I run my twisted application as follows:

twistd --pidfile ./twistd.pid -l $HOME/logs/my_application.log -oy service.tac

I found that it does not log anything sent through python logging . I noticed that there is "PythonLoggingObserver" in twisted, but redirects twisted logs to the log module.

I would like to find out how I can get all the logs (regardless of the log module) to go to the log file specified by the "-l" command in twistd. I suspect my logs are being written to the stdout daemon.

Here's how I initialize python logging in a .tac file:

import logging

LOG_LEVEL = logging.DEBUG

logger = logging.getLogger(module_name)
logger.setLevel(LOG_LEVEL)
logging.basicConfig(level=LOG_LEVEL)
+4
source share
1 answer

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
>>> 
+1

All Articles