tags:

views:

42

answers:

2

My system is set to EDT in Linux, and I can confirm this in Python with datetime.now(). However the logger is outputting 4 hours ahead. What could be the cause of this?

EDIT: Logging config looks like this:

logging.basicConfig(level=logging.DEBUG)
lf = logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")

mylogger = logging.getLogger('mylogger')
mylogger .setLevel(logging.DEBUG)

lsh = logging.StreamHandler()
lsh.setLevel(logging.DEBUG)
lsh.setFormatter(lf)
mylogger.addHandler(lsh)
+1  A: 

Your logger is using UTC time. If you show us your code it would be possible to say exactly why.

SilentGhost
Edited with more details of the logging config.
Rhubarb
Do you need more code than what I've showed? That is about all there is with relation to the logger.
Rhubarb
@rhubarb: what version of Python are you using?
SilentGhost
Version 2.6 of python
Rhubarb
@rhubarb: by default logging uses `time.localtime` to produce time stamp. You could inspect `logging` module yourself to make sure that nothing is changed there, it's usually located at `/usr/lib/python2.6/logging.py/__init__.py`
SilentGhost
A: 

I think it is significant that 4 hours ahead is GMT for you. Poking around logging's code - it seems that it uses time rather than datetime. Apparently they work differently in figuring out the localtime.

What does the following output?:

import time
print time.tzname

AFAIK, that controls the offset used by logging. According to the documentation, you want to tweak your "system's zoneinfo database to specify the timezone rules" (man tzfile).

spenthil
It says EDT, EST. So that doesn't seem to be the problem.
Rhubarb