#!/usr/bin/python

###
# Domotica monitoring daemon.
# responsible for all features which require regular polling of the PLC (i.e.
# everything we can't do from the web interface)
###

import daemon
import optparse
import time
import logging

import s7
import domotica.settings as settings

from pollers import AlarmPoller

POLL_INTERVAL = 5

def poll(s7conn, pollers):
    for poller in pollers:
        poller.poll(s7conn)

def connect():
    return s7.S7Comm(settings.PLC_IP)

def main():
    parser = optparse.OptionParser()
    parser.add_option("-f", "--foreground", action="store_true",
            dest="foreground", help="Do not daemonize", default=False)
    parser.add_option("-d", "--debug", action="store_true",
            dest="debug", help="Debug logging", default=False)
    (options, args) = parser.parse_args()

    if not options.foreground:
        d = daemon.DaemonContext(prevent_core=False)
        d.open()

    if options.debug:
        logging.basicConfig(level=logging.DEBUG)
    else:
        logging.basicConfig(level=logging.INFO)

    pollers = [
            AlarmPoller()
        ]

    s7conn = connect()

    while True:
        try:
            poll(s7conn, pollers)
        except s7.S7Exception, e:
            if e.errno() == s7.S7Exception.ERR_CONNECTION_CLOSED:
                logging.warn("Connection lost. Reconnecting...")
                s7conn = connect()
            else:
                logging.error("Unknown error: %s", e)
                raise

        time.sleep(POLL_INTERVAL)

if __name__ == "__main__":
    main()

@@ -473,16 +473,226 @@
 LC_IP)%0A%0A
+def setup_logger(options):%0A    lvl = logging.INFO%0A    if options.debug:%0A        lvl = logging.DEBUG%0A%0A    fmt = %22%25(asctime)s:%25(levelname)s:%25(module)s:%25(message)s%22%0A    logging.basicConfig(level=lvl, format=fmt)%0A%0A
 def main
@@ -1144,131 +1144,28 @@
     
-if options.debug:%0A        logging.basicConfig(level=logging.DEBUG)%0A    else:%0A        logging.basicConfig(level=logging.INFO
+setup_logger(options
 )%0A%0A 

Change logging format