I have a Jython script that uses the Python logging module for logging. On one machine the script logs fine and on the other the time logged is shifted five hours into the future. Presumably this has to do with the machine being at GMT-5. What do you think can cause this issue?
Here’s how I create the logging object:
log = logging.getLogger("my_log")
log.setLevel(logging.DEBUG)
handler = logging.handlers.RotatingFileHandler(
log_file,
maxBytes=log_size,
backupCount=logs_count)
log_format = logging.Formatter("%(asctime)s:%(levelname)s:%(message)s")
handler.setFormatter(log_format)
handler.setLevel(logging.DEBUG)
log.addHandler(handler)
I did look at the log_format.converter function. I did make sure the time is set properly on the problematic machine. And I did make sure Python prints the correct time in the Python shell.
Edit: If I look at time.localtime() from the Python shell (2.4.3) then I get a tuple with correct local time values. If I look at time.localtime() from within the Jython script (2.5.2RC1) then I see the time in GMT.
I think I found the issue. Apparently Java itself was getting the time wrong, and the reason was that the timezone was not set properly for Java on the problematic machine.
export TZ='US/East'in /etc/profile.d/java.sh seems to solve the issue.This took me some time to figure out because running
datefrom the shell output the correct local time and timezone information. Python too was able to figure out the timezone correctly.Thanks guys!