Welcome! Log In Create A New Profile

Advanced

PATCH: $time_custom supports a custom log timestamp

Wayne Davison
August 24, 2009 02:02PM
Hi there. The company I work for, SourceForge, wanted the ability to
have a custom timestamp in a log file, so I created a patch for this. I
have been authorized to release it back to the nginx community. See
what you think of my design and let me know if you have any ideas for
improvements.

The patch implements the following:

For every named log format there may be defined a custom timestamp format
that will be passed to strftime() for expansion. This string is accessed
via $time_custom instead of $time_local. (It defaults to expanding to an
empty string unless the user specifies a time_custom_format value for the
named log format.) Inside the custom format one extra variable expansion
is supported: the use of "$ms" will substitute a 3-digit milliseconds
value at that point.

For example:

log_format main '$remote_addr - $remote_user [$time_custom] "$request" '
'$status $body_bytes_sent "$http_referer" '
'"$http_user_agent" "$http_x_forwarded_for"';

time_custom_format main '%d/%b/%Y:%H:%M:%S.$ms %z';

That defines a log format that is like $time_local except that it gets
millisecond logging resolution. Obviously, the string doesn't need to
be quite so similar to the default, but you get the idea.

Here's the patch:

http://opencoder.net/nginx-time_custom.patch

The code caches the strftime() expansion so that all loggers using the
named log format cause strftime() to be called at most once per second.

Please let me know what you think.

..wayne..
Subject Author Posted

PATCH: $time_custom supports a custom log timestamp

Wayne Davison August 24, 2009 02:02PM

Re: PATCH: $time_custom supports a custom log timestamp

jasiu85 August 24, 2009 03:20PM

Re: PATCH: $time_custom supports a custom log timestamp

Wayne Davison August 24, 2009 04:04PM

Re: PATCH: $time_custom supports a custom log timestamp

Cliff Wells August 24, 2009 03:27PM

Re: PATCH: $time_custom supports a custom log timestamp

Marcus Clyne August 24, 2009 08:50PM

Re: PATCH: $time_custom supports a custom log timestamp

Wayne Davison August 25, 2009 01:31AM

Re: PATCH: $time_custom supports a custom log timestamp

Wayne Davison August 24, 2009 07:58PM



Sorry, only registered users may post in this forum.

Click here to login

Online Users

Guests: 170
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready