Rotating Access Logs with $date_local

Maxim Dounin mdounin at mdounin.ru
Tue Oct 28 15:54:19 UTC 2014


Hello!

On Tue, Oct 28, 2014 at 08:39:04AM -0700, Igal @ getRailo.org wrote:

> How can I format the $date_local string?  I want it to be date only,
> like 20141028, and then use it in the filename for access log.
> 
> Is that possible?  and if not, why?  seems like a simple solution to a
> problem that many users face and resort to external tools etc.

It is possible - you can use construct appropriate variable, e.g., 
by using map{} and $time_local.  (The $date_local won't work for 
you as you won't be able to set format without SSI.)

On the other hand, it's not recommended as it implies unneeded 
work on each request.  It's better to configure proper log 
rotation instead, see:

http://en.wikipedia.org/wiki/Log_rotation
http://nginx.org/en/docs/control.html#logs

On UNIX systems there are system tools to rotate logs, like 
newsyslog or logrotate, and configuring log rotation is as easy as 
adding a line to appropriate configuration file.  There are likely 
something available for Windows, too.

-- 
Maxim Dounin
http://nginx.org/



More information about the nginx mailing list