0
votes

I am trying to set up the RotatingFileHandler in Python 2.7 with module logging, but no matter what I do, I can only get the top level script to write to the log file.

here's my code in my top Script:

import logging
import Lib.download as d

LOG_FILE = public_dir + "\script2.log"

log = logging.getLogger('Script_2')
log.setLevel(logging.DEBUG)

rotate_handler = handlers.RotatingFileHandler(LOG_FILE, maxBytes = 5000, backupCount=5)
log_format = logging.Formatter('%(asctime)s %(name)-8s:%(levelname)s:%(message)s')
rotate_handler.setFormatter(log_format)

log.addHandler(rotate_handler)

log.debug('Launching meat of script_2')
d.some_function()
log.info('script_2 completed successfully')

code in one module 'download':

import logging
log = logging.getLogger('script_2.download')

def some_function():
    log.debug('doing some_function')

My output does not reflect the module logging

2014-01-13 12:56:04,428 Script_2:DEBUG:Launching the meat of script_2
2014-01-13 12:56:05,005 Script_2:INFO:Script_2 completed successfully

What am I missing? Logging modules worked just fine until I added the RotatingFileHandler...

I've tried other solutions from the forums including Python logging over multiple files

but no dice. Any help?

1

1 Answers

1
votes

Not sure if you figured it out but based on the information provided it looks like you have a mismatch with your logger's names.

In your main script you defined the logger to be 'Script_2' and in your 'download' module you are referencing the 'script_2.download'. So the parent is capitalized and the child is not.

So there are actually two different loggers that do not share the same hierarchy.