Neither pdb or print() displays the bug

Ethan Furman ethan at stoneleaf.us
Tue Jun 1 17:07:15 EDT 2021


On 6/1/21 1:42 PM, Rich Shepard wrote:

 > When I run it this is the output:
 > $ python activitytypes.py 2021-06-01 13:39:10,219 -DEBUG - Start of Program
 > 2021-06-01 13:39:15,229 -DEBUG - End of Program

Well, you only had two logging statements in that code -- logging is like print: if you want to see it, you have to call it:

     logging.info('start of xx procedure')
     logging.info('spam = %s', spam)         # note the comma and not actual %-interpolation

 > Obviously I have much to learn about using python's logging capabilities.
 > I'll keep looking.

I'm certainly not an expert, but this is how I do it:

     from logging import INFO, getLogger, Formatter, handlers

     logger = getLogger()
     logger.setLevel(INFO)
     _handler = handlers.TimedRotatingFileHandler(
             virtualenv / 'var/log/openerp/continuous_sync_records.log',
             when='midnight',
             backupCount=30,
             )
     _formatter = Formatter('%(asctime)s %(funcName)-25s %(message)s')
     _handler.setFormatter(_formatter)
     logger.addHandler(_handler)
     del _handler, _formatter

and then in my code:

     logger.info('failure converting %r to %r', target_bmp_file, target_png_file)

--
~Ethan~


More information about the Python-list mailing list