Re: logging producing redundant entries



Jed Parsons wrote:

I'm using the logging module for the first time. I'm using it from
within Zope Extensions.

My problem is that, for every event logged, the logger is producing
multiple identical entries with the timestamp the same down to the
millisecond.

Is this something I'm doing wrong?

Log snippet:

2006-03-30 16:20:14,173 INFO: Login: Jed Parsons
2006-03-30 16:20:14,173 INFO: Login: Jed Parsons
2006-03-30 16:20:14,173 INFO: Login: Jed Parsons
2006-03-30 16:20:14,173 INFO: Login: Jed Parsons
2006-03-30 16:20:14,173 INFO: Login: Jed Parsons
2006-03-30 16:20:14,173 INFO: Login: Jed Parsons
2006-03-30 16:20:14,173 INFO: Login: Jed Parsons
2006-03-30 16:20:14,173 INFO: Login: Jed Parsons

I would like only one of the above lines in my log file; not all those
copies.

I'm using this simple logging setup at the top of a zope Extension module:

import logging
# basicConfig for python 2.3
logging.basicConfig()
_logger = logging.getLogger("login")
_logger.setLevel(logging.DEBUG)
_handler = logging.FileHandler(LOG_ROOT, 'login.log'))
_formatter = logging.Formatter("%(asctime)s %(levelname)s:
%(message)s")
_handler.setFormatter(_formatter)
_logger.addHandler(_handler)

So these are global to the module. The log lines above were produced by
what I expected would be a single call to _logger.info() in a function
in the module:

_logger.info("Login: %s %s" % (firstname, lastname))

Can anyone explain what I'm doing wrong? Many thanks,

Please cut and paste -- the FileHandler arguments are wrong and there is an
extra ')'. As alex23 said, basicConfig() adds a handler, but that logs to
stderr by default. You seem to be executing the code given above multiple
times. You can verify that by prepending your snippet with

f = open("metalog.txt", "a")
f.write("configuring handler\n")
f.close()

If metalog.txt contains multiple lines after your program has terminated
(you may have to shut down Zope -- don't know about that), a quick fix
might be

import logging
if not logging.root.handlers:
# your setup code

Peter
.



Relevant Pages

  • Re: Future ISPF directions (was: Re: How Was Share?)
    ... Shutting off propagation of the Enqueue for PROFILE would only ... apply to logging on to multiple systems in the sysplex. ... LOG might be a bigger issue if you wanted multiple concurrent ... For IBM-MAIN subscribe / signoff / archive access instructions, ...
    (bit.listserv.ibm-main)
  • Re: lew? 2 qq
    ... Everyone writes to the same channel, and the logging overhead to stderr is incurred with every call; that can have an adverse impact on performance. ... you have to invent your own formats, disentangle all the output from multiple sources, disentangle important output from less so, and you can't selectively suppress some log output and not other. ... All less critical messages ("WARNING", "DEBUG", etc.) not only are not emitted, they have negligible impact on production performance. ... Logging is configurable at deployment time via an external resource file, so you don't even have to hard-code all that control. ...
    (comp.lang.java.help)
  • Re: Logging 0.7.0 (Quixotic Starfish)
    ... Multiple Rails processes can ... You can also use the Syslog appender in Logging and dump to the syslog ... This is good for collecting logs from multiple machines. ...
    (comp.lang.ruby)
  • Re: Trace debugging in run-time (re-direct Debug.Print to a file?)
    ... You could use a file logging class that is safe to use with multiple ... Note that I'm not redirecting you to a file-based logging as it has some ... overhead and possible issues as Windows doesn't update the log file ...
    (microsoft.public.vb.general.discussion)
  • Re: line duplication using logging to file
    ... Meanwhile I have written the logging function from scratch and it works ... This means that the multiple line copy is not due to the multiple ... Obviously there is some understantding of the logging module that I am ... here is the pyparsing program I used to do this analysis) ...
    (comp.lang.python)

Loading