0

This is how I run the daemon:

        import daemon
        logger = logging.getLogger('time_logging_daemon')
        handler = logging.handlers.SysLogHandler(
            facility=logging.handlers.SysLogHandler.LOG_DAEMON, address="/dev/log")
        logger.addHandler(handler)
        logger.setLevel(logging.INFO)
        logger.info("Before")
        with daemon.DaemonContext():
            logger.info("Before daemonizing.")
            try:
                bot.start()
            except:
                logger.info("crashed")

Unfortunately all I get in the logs is this:

Apr 3 22:33:06 mybot Before daemonizing.

It doesn't seem to be crashing, and I can see it in ps aux | grep python. But the code just doesn't function as its supposed to be. How can errors be thrown and captured, so I can see if anything isn't right?

Houman
  • 64,245
  • 87
  • 278
  • 460
  • 1
    Try logging the [exception](http://stackoverflow.com/questions/5191830/best-way-to-log-a-python-exception); ```logger.exception```. Also, how is 'bot' being defined? Maybe you can try logging in the bot, or raising exceptions from that object. – willnx Apr 03 '16 at 22:44
  • http://stackoverflow.com/questions/14674733/python-daemon-keep-logging – Dan Kruchinin Apr 03 '16 at 22:55
  • Thanks both solutions were helpful. Especially defining the logger inside Daemon context was the key. – Houman Apr 06 '16 at 07:13

0 Answers0