On 12/29/2011 04:13 AM, rail shafigulin wrote:
has anyone used python logger before? i'm trying to adapt it for my
workplace. right now it is pretty simplistic for me. i'm trying to
generate extra output by the LoggerAdapter. however i'm getting errors.
specifically i get the following message:
Traceback (most recent call last):
File "/usr/lib/python3.1/logging/__init__.py", line 770, in emit
msg = self.format(record)
File "/usr/lib/python3.1/logging/__init__.py", line 650, in format
return fmt.format(record)
File "/usr/lib/python3.1/logging/__init__.py", line 438, in format
record.message = record.getMessage()
File "/usr/lib/python3.1/logging/__init__.py", line 308, in getMessage
msg = msg % self.args
TypeError: not all arguments converted during string formatting
Please don't trim the traceback, your traceback is missing the top-most
trace which will be the most useful in identifying your current problem.
Your problem is here:
mylogadapter.info('this is a log message', testinfo)
The first argument of the logging function is used as a format string
for the following arguments. Since you're passing testinfo as a second
argument to .info(), you need a placeholder in your first argument, e.g.:
mylogadapter.info('this is a log message, testinfo: %s', testinfo)
the logger will convert testinfo into a string and substitute that to %s
in the format string.
Also, for your TestInfo class, you may want to look into
collections.namedtuple.
_______________________________________________
Tutor maillist - Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor