I tried to define a global logging for a web2py app. The problem with
that is that if I place the following code in my default.py controller
or db.py model then in both cases its executed more than
once...resulting into having every log line written multiple times
into the log file.

either starting the default.py or db.py with those lines is yielding
the same result
    import logging, logging.handlers

    # Make a global logging object.
    lox = logging.getLogger("log")
    lox.setLevel(logging.DEBUG)

    # This handler writes everything to a file.
    h1 = logging.FileHandler("/var/log/myapp.log")
    f = logging.Formatter("%(levelname)s %(asctime)s %(funcName)s %
(lineno)d %(message)s")
    h1.setFormatter(f)
    h1.setLevel(logging.DEBUG)
    lox.addHandler(h1)

    # This handler emails me anything that is an error or worse.
    h2 = logging.handlers.SMTPHandler('localhost', 'l...@test.com',
['tobenotif...@test.com'], 'ERROR log')
    h2.setLevel(logging.ERROR)
    h2.setFormatter(f)
    lox.addHandler(h2)

log usage example in controller...
    def index():
        log = logging.getLogger("log")
        log.debug("starting...")
        ....do something
        log.debug("finishing...")
        return()

log file looks like:
DEBUG 2009-06-04 20:27:45,617 index 1 starting...
DEBUG 2009-06-04 20:27:45,617 index 1 starting...
DEBUG 2009-06-04 20:27:45,617 index 1 starting...
DEBUG 2009-06-04 20:27:50,617 index 1 finishing...
DEBUG 2009-06-04 20:27:50,617 index 1 finishing...
DEBUG 2009-06-04 20:27:50,617 index 1 finishing...

how can I fix the 'multiple problem' ?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to