logging
Vinay Sajip
vinay_sajip at yahoo.co.uk
Tue Sep 7 16:52:34 EDT 2004
Ajay <abra9823 at mail.usyd.edu.au> wrote in message news:<mailman.2555.1093674935.5135.python-list at python.org>...
> hi!
>
> in my web app. i log debug messages to a file. however, sometimes the
> messages appear more than once even though the code in which the log
> statement appears gets executes only once
> i have a utilities.py file which defines a getLogger() method as follows
>
> logger = logging.getLogger('../logs/umapp')
> hdlr = logging.FileHandler('../logs/umapp.log')
> os.system("chmod 755 ../logs/umapp.log")
> formatter = logging.Formatter('%(asctime)s %(levelname)s %(message)s')
> hdlr.setFormatter(formatter)
> logger.addHandler(hdlr)
> logger.setLevel(logging.INFO)
> return logger
>
> all my cgi scripts the the start make the call - logger =
> utilities.getLogger()
>
> the scripts then log debug messages during different stages of their
> execution.
>
> however, some of these debug messages appear 2 or 3 times on the log file.
> i have verified that the particular code block in which the log statement
> is present is executed only once
>
> any ideas
Make sure you don't add the same handler several times to a given
logger or to the root. If you do this, the logging messages get
handled (=> displayed) multiple times.
Regards
Vinay Sajip
More information about the Python-list
mailing list