Logging with Custom Levels not working

Didymus lynto28 at gmail.com
Fri Feb 20 08:29:44 EST 2015


On Friday, February 20, 2015 at 4:25:50 AM UTC-5, Ian wrote:
> > On Wednesday, February 18, 2015 at 3:16:40 PM UTC-5, Ian wrote:
> >> > def perror(self, message, *args, **kws):
> >> >     """ Performance Error Message Level """
> >> >     # Yes, logger takes its '*args' as 'args'.
> >> >     self._log(PERROR_NUM, message, args, **kws)
> >> >
> >> > logging.Logger.perror = perror
> >>
> >> I think you need to call self.log, not self._log. The _log method
> >> appears to assume that the level check has already been performed. You
> >> really shouldn't be calling it directly anyway, as the leading _ is an
> >> indication that the method is not part of the public API.
> >
> > Yes, I had tried that and get:
> >
> > Logged from file log5.py, line 21
> > Traceback (most recent call last):
> >   File "/usr/lib64/python2.7/logging/__init__.py", line 851, in emit
> >     msg = self.format(record)
> >   File "/usr/lib64/python2.7/logging/__init__.py", line 724, in format
> >     return fmt.format(record)
> >   File "/usr/lib64/python2.7/logging/__init__.py", line 464, in format
> >     record.message = record.getMessage()
> >   File "/usr/lib64/python2.7/logging/__init__.py", line 328, in getMessage
> >     msg = msg % self.args
> > TypeError: not all arguments converted during string formatting
> 
> log and _log don't have the same function signature. Specifically, log
> takes *args and _log just takes args (as noted in the comment on the
> preceding line).

Hi,

    I found the problem. I wasn't setting the level on the Handlers. Need to have:

fileHandler.setLevel(level)
consoleHandler.setLevel(level)

Once that was added to the SetLogging() function, it was printing out the correct levels. The rootLogger.setLevel(level) wasn't getting propagated to the Handlers...

     Thanks for all the help!
              Tom



More information about the Python-list mailing list