I'm trying to daemonize a simple Twisted application which uses Python2.7 standard library logger.
Here is the setup :
Python application file (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 application file (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)
Log observer file (daemonlog.py) :
from twisted.python import log
def logger():
return log.PythonLoggingObserver().emit
Launching the application with :
python run.py
everything works fine and log messages are correctly filed and displayed (according to the logger configuration).
Trying to daemonize with :
twistd -y daemon.tac --logger=daemonlog.logger
The daemon starts fine, I can see the twistd.pid file created (with the correct pid number), the daemon running in the ps -ef command results, but I can't see any log files (neither twistd.log or log file as created by the application when it is started normally without twistd).
In the end, I would like to use only Python's standard library logger and kind of "by-passing" twistd logger.
I'm probably missing something or misundertsanding and any help would be appreciated.