simple question

A

Ajay

hi!

i have created a logger
self.logger = logging.getLogger('smsapp')
hdlr = logging.FileHandler('logs/smsapp.log')
formatter = logging.Formatter ('%(asctime)s %(levelname)s %(message)s')
hdlr.setFormatter(formatter)
self.logger.addHandler(hdlr)
self.logger.setLevel(logging.DEBUG)

when i log an error
self.logger.error("Illegal date index, " str(dateIndex))
i get an error in my code
Traceback (most recent call last):
File "/usr/local/lib/python2.3/logging/__init__.py", line 674, in emit
msg = self.format(record)
File "/usr/local/lib/python2.3/logging/__init__.py", line 567, in format
return fmt.format(record)
File "/usr/local/lib/python2.3/logging/__init__.py", line 362, in format
record.message = record.getMessage()
File "/usr/local/lib/python2.3/logging/__init__.py", line 233, in
getMessage
msg = msg % self.args
TypeError: not all arguments converted during string formatting

dateIndex is an int

thanks

cheers
 
P

Peter Otten

Ajay said:
self.logger.error("Illegal date index, " str(dateIndex))

I think you meant

self.logger.error("Illegal date index ", str(dateIndex))

error(fmt, arg1, arg2, ..., argN)

is just a convenient alternative to

error(fmt % (arg1, arg2, ..., argN))

Therefore

self.logger.error("Illegal date index %s", dateIndex)

or

self.logger.error("Illegal date index " + str(dateIndex))

should both work.

Peter
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,228
Latest member
MikeMichal

Latest Threads

Top