Logging with Custom Levels not working
Ian Kelly
ian.g.kelly at gmail.com
Fri Feb 20 04:16:39 EST 2015
On Thu, Feb 19, 2015 at 11:16 AM, Didymus <lynto28 at gmail.com> 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).
More information about the Python-list
mailing list