Log4cpp: Print date in UTC/GMT time zone

230 views Asked by At

I am working with log4cpp. Is there a way to print the timestamps/dates in log4cpp converted to GMT/UTC timezone ?

At the moment I use %d which currently prints out the local time, however I want this in UTC/GMT.

1

There are 1 answers

0
sehe On

According to this old thread, there is no support:

ankit tandon пишет:

Hi All , Currently is there any way to print the timestamps/dates in log4cpp converted to GMT/UTC timezone. I read somewhere that using "%d" prints the date in UTC but we are still getting our local system (US) time. Any help regarding this will be deeply appreciated.

No, there is no way to print UTC time using PatternLayout. But you can write your own appender that will print UTC timestamps/date.

That is at odds with documentation claiming that %d prints UTC, and %D local time.

So I checked the code in log4cpp-1.1.3.tar.gz for the facts. It looks like it's always localtime:

std::time_t t = event.timeStamp.getSeconds();
localtime(&t, &currentTime);

Perhaps you could simply patch that line to use gmtime instead.