loggin

A

Ajay

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

thanks
cheers
 
V

Vinay Sajip

Ajay said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top