Discussion:
How to log the time in the UTC time format?
naltimari
2009-11-30 21:31:20 UTC
Permalink
I need my logs in UTC time format, but nginx by default uses the local time format (I guess in GMT format).

Can it be done? How?

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,26862,26862#msg-26862
Maxim Dounin
2009-11-30 21:52:24 UTC
Permalink
Hello!
Post by naltimari
I need my logs in UTC time format, but nginx by default uses the local time format (I guess in GMT format).
Can it be done? How?
There is no "UTC time format". If you mean time zone - just set
appropriate one in environment while starting nginx (via TZ
environment variable).

Maxim Dounin
naltimari
2009-11-30 22:06:57 UTC
Permalink
Well, maybe you're right, but what I need is the same time that would come from 'date -u' command.

Right now, my log time format is like this: 30/Nov/2009:16:14:39 -0200

When I need this: Mon Nov 30 18:14:39 UTC 2009

Can I change the syntax/format in which the date is written to the log?


I appreciate your help.
[]s

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,26862,26870#msg-26870
Maxim Dounin
2009-11-30 23:29:31 UTC
Permalink
Hello!
Post by naltimari
Well, maybe you're right, but what I need is the same time that would come from 'date -u' command.
Right now, my log time format is like this: 30/Nov/2009:16:14:39 -0200
It's date and time in common log format
(http://en.wikipedia.org/wiki/Common_Log_Format).
Post by naltimari
When I need this: Mon Nov 30 18:14:39 UTC 2009
Can I change the syntax/format in which the date is written to the log?
No, the is no way to specify arbitrary format for time. The only
available options out-of-the box is $time_local (time in common log
format) and $msec (seconds since the Epoch with milliseconds
resolution).

The only option for now is to use something like embedded perl to
construct time in arbitrary format, something like

perl_set $tt 'sub { scalar localtime }';

and then use it in logs via appropriate log_format. But I don't
really think it's a good way to go.

BTW, could you please explain why do you need time in this particular
format?

Maxim Dounin
naltimari
2009-11-30 23:52:22 UTC
Permalink
Post by Maxim Dounin
The only option for now is to use something like
embedded perl to construct time in arbitrary format
perl_set $tt 'sub { scalar localtime }';
Although it is not appropriate for me, thanks for the input, I never knew this could done!

Well, I'm going to parse the log myself, so I can always change the time format later.

I'm really not sure if UTC will make any difference, I was only looking it up as a client request.

Thanks for your help!
[]s

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,26862,26886#msg-26886
rmalayter
2009-12-04 15:11:19 UTC
Permalink
Maxim Dounin Wrote:
-------------------------------------------------------
Post by Maxim Dounin
BTW, could you please explain why do you need time
in this particular
format?
Many log parsing and event correlation tools need the time with miliseconds, which $time_local doesn't produce. However, many of these tools also cannot hanlde the "number if miliseconds since start of UNIX time" that nginx produces with $msec.

A nice option would be to output ISO-8601 format time stamps in logs, which just about every tool can handle, such as this:
2009-12-04T13:48:22.432Z

These are also human-readable time stamps that include miliseconds, which is nice. Even Microsoft IIS can do this.

See:
http://en.wikipedia.org/wiki/ISO_8601

Posted at Nginx Forum: http://forum.nginx.org/read.php?2,26862,27966#msg-27966
Igor Sysoev
2009-12-01 07:18:54 UTC
Permalink
Post by Maxim Dounin
Hello!
Post by naltimari
I need my logs in UTC time format, but nginx by default uses the local time format (I guess in GMT format).
Can it be done? How?
There is no "UTC time format". If you mean time zone - just set
appropriate one in environment while starting nginx (via TZ
environment variable).
BTW, TZ can be set in nginx.conf at global level:

env TZ=UTC;
--
Igor Sysoev
http://sysoev.ru/en/
Loading...