How to log the time in the UTC time format?

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:

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:

Maxim D. Wrote:

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:

Maxim D. Wrote:

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:

Posted at Nginx Forum:

Hello!

On Mon, Nov 30, 2009 at 04:31:20PM -0500, naltimari wrote:

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 D.

On Tue, Dec 01, 2009 at 12:52:24AM +0300, Maxim D. wrote:

environment variable).
BTW, TZ can be set in nginx.conf at global level:

env TZ=UTC;


Igor S.
http://sysoev.ru/en/

Hello!

On Mon, Nov 30, 2009 at 05:06:57PM -0500, naltimari wrote:

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
(Common Log Format - Wikipedia).

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 D.