Running a Python script from crontab

Astley Le Jasper Astley.lejasper at gmail.com
Wed Dec 3 05:28:35 EST 2008


Ok ... this is odd.

I tried gregory's suggestion of redirecting the stdout & stderr to a
text file. This worked. I could see all the logging information.
However, there was no error to see this time ... the application
worked completely without any problems.

I also then tried Jon's suggestion of attaching to the console ...
this also allowed me to see all the logging info as it went through.
Again, there were no problems as the application worked without any
problems.

Which suggests that it's the logging module or something with the
output streams.

Here is my logging setup in the primary module. It directs info to the
main console and also to a logging file.....

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
#Set up logging

log = logging.getLogger('scrape_manager')

log.setLevel(logging.INFO)



my_filename = ss.compact_date() + '_' + time.strftime("%H%M")

ensure_dir('logs/')
 #Checks to see if the dir is there and creates it if not
log_file = 'logs/systemlog_' + my_filename + ".log"


console_h = logging.StreamHandler()

file_h = logging.FileHandler(log_file,'w')


log.addHandler(console_h)

log.addHandler(file_h)


console_fmt = logging.Formatter('%(levelname)s (%(threadName)-10s) %
(module)s %(message)s',)

file_fmt = logging.Formatter('%(asctime)s\t%(levelname)s\t(%
(threadName)-10s)\t%(module)s\t%(message)s',)


console_h.setFormatter(console_fmt)

file_h.setFormatter(file_fmt)

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>

I also call this from an auxiliary module that is use my the primary
module:

log = logging.getLogger('scrape_manager')

If I change the name of the logger in the auxilary module then I loose
all the loggiing information but the application works.

What am I doing wrong with the logging setup? I can't see how I would
change it.

ALJ



More information about the Python-list mailing list