Thursday, February 24, 2011

Geez python logging can be a pain

Geez python logging can be a pain in the ass making it difficult for novice programmers to debug stuff e.g.

This code ...

            logging.info ('>>>>>>>>>>>>' )
            logmsg = '339 init_facebook user email is ' , user.email.encode('ascii', 'ignore')
            logging.info ( logmsg )
            logging.info ('<<<<<<<<<<<' )

... works. See ...


INFO     2011-02-25 07:37:39,411 main.py:340] ('339 init_facebook user email is ', 'red.cricket.blog@gmail.com')
INFO     2011-02-25 07:37:39,411 main.py:341] <<<<<<<<<<<
INFO     2011-02-25 07:37:39,436 main.py:294] BaseHanlder render called

But this code  ...

            logging.info ('>>>>>>>>>>>>' )
            logging.info ( '339 init_facebook user email is ' , user.email )
            logging.info ('<<<<<<<<<<<' )

... gets this error message ...

INFO     2011-02-25 07:42:00,040 main.py:337] >>>>>>>>>>>>
Traceback (most recent call last):
  File "/usr/lib/python2.6/logging/__init__.py", line 768, in emit
    msg = self.format(record)
  File "/usr/lib/python2.6/logging/__init__.py", line 648, in format
    return fmt.format(record)
  File "/usr/lib/python2.6/logging/__init__.py", line 436, in format
    record.message = record.getMessage()
  File "/usr/lib/python2.6/logging/__init__.py", line 306, in getMessage
    msg = msg % self.args
TypeError: not all arguments converted during string formatting
INFO     2011-02-25 07:42:00,041 main.py:342] <<<<<<<<<<<

No comments:

Post a Comment