Logging with Custom Levels not working

Didymus lynto28 at gmail.com
Thu Feb 19 13:16:10 EST 2015


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


I also added:

ll = rootLogger.getEffectiveLevel()

which send back the correct level, but it's still printing out everything...

  -Tom



More information about the Python-list mailing list