Problem with logging - python 2.4

A forum for general discussion of the Python programming language.

Problem with logging - python 2.4

Postby rhugga » Mon Jun 16, 2014 4:45 pm

I'm stuck using python 2.4 for this project and having odd issue with logging. It was working fine and one point and I started expanding the use of logging in my code and it broke at some point. I have now dummied it back down to just this simple stanza:

Code: Select all
import logging

logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)s %(message)s', filename='/var/tmp/my.log', filemode='w')
logging.debug(" script initiated")
logging.debug(" log file %s opened with level = %s " % (LOGFILE, LOGLEVEL))



The log file gets created but has size = 0. I've checked the code for non-printing characters. I have vim set to expand tabs to spaces and verified all this with 'cat -vet'. The script is being run as root.

Just scratching my head on this one.
Last edited by Yoriz on Mon Jun 16, 2014 4:48 pm, edited 1 time in total.
Reason: First post lock.
rhugga
 
Posts: 1
Joined: Mon Jun 16, 2014 4:40 pm

Re: Problem with logging - python 2.4

Postby micseydel » Mon Jun 16, 2014 8:33 pm

I modified what you posted to try it locally, and ended up with this
Code: Select all
import logging

LOGFILE = 'my.log'

logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)s %(message)s', filename=LOGFILE, filemode='w')
logging.debug(" script initiated")
logging.debug(" log file %s opened " % LOGFILE)

This seems to work as expected for me on a newer version of Python (I didn't run it as root or log to anywhere that required it). Does this work for you? If it does, but it doesn't for root, but you post the complete and exact code you have?
Join the #python-forum IRC channel on irc.freenode.net!
User avatar
micseydel
 
Posts: 1131
Joined: Tue Feb 12, 2013 2:18 am
Location: Mountain View, CA


Return to General Discussions

Who is online

Users browsing this forum: No registered users and 3 guests