PATCH: $time_custom supports a custom log timestamp

Cliff Wells cliff at
Mon Aug 24 23:27:38 MSD 2009

Hi Wayne,

Off-topic, but would SF be willing to provide a small blurb that I can
add to the wiki propaganda?  Something along the lines about how Nginx
single-handedly saved SF from destruction by an asteriod or perhaps a
falling piano would fit the bill nicely, but if you can't provide that,
then some general info of how SF is utilizing Nginx and what benefit SF
derives from Nginx (vs some other web server/proxy) would be nice as

You can see the front page of the wiki ( for an
idea of what we're looking for.


On Mon, 2009-08-24 at 11:02 -0700, Wayne Davison wrote:
> 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:
> 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..

More information about the nginx mailing list