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:
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.
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.)
Thank you for your prompt reply. I do not have much experience with
nginx configuration so I have a follow up question.
I looked up the docs about map{} at Module ngx_http_map_module and I tried to
follow the example. I see that $time_local is (in my local time)
“28/Oct/2014:09:30:35 -0700” so I want from that the year, month, and
day. as an experimentation, I tried to add the following:
map $time_local $date {
~\w{11} 0;
}
but I get an error that the ‘{’ character is not valid at that
position. so I tried instead
~\w\w\w\w\w\w\w\w\w\w\w 0;
and then nginx starts up but $date is an empty string.
Can you point me in the right direction? and if it’s not too
complicated make a suggestion regarding the regex that I would need
since I must break the $time_local to year, month, and day (or do I need
to create 3 map{} variables for that? now that would be inefficient…)
On the other hand, it’s not recommended as it implies unneeded
work on each request.
With the amount of traffic that I get, and the way that nginx is
handling it, these few added microseconds should not be an issue IMO and
it would be a much easier solution to implement than an external process
that may or may not work properly.
On Tue, Oct 28, 2014 at 09:48:32AM -0700, Igal @ getRailo.org wrote:
Hi there,
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.)
Thank you for your prompt reply. I do not have much experience with
nginx configuration so I have a follow up question.
The thread starting at can a map + regex be used to generate variables for YYYY-MM-DD-HH? is not
entirely dissimilar to this one. You may find useful answers there.
The most useful is probably “don’t do that”; but since you want to do
that, you can probably use one “if” or multiple "map"s. f
Thank you for your reply.
You mentioned multiple maps but why can’t it be done with a single one?
@echo off
::Parse the time variable into timeStamp
FOR /F “tokens=1-4 delims=/:., " %%J IN (”%time%“) DO SET
timeStamp=%%J%%K%%L
::Parse the date variable into dateStamp, YYYYMMDD
FOR /F “tokens=2-4 delims=/:.- " %%J IN (”%date%”) DO SET
dateStamp=%%L%%K%%J
set datename=%dateStamp%
::Parse the name again and get rid of the spaces
FOR /F “tokens=1-4” %%J IN (“%datename%”) DO SET datename=%%J%%K%%L
IF “%datename%”==“” set datename=EMPTY
cd /d x:\logs
FOR %%G IN (*.log) DO ren “%%G” “%datename%_%%G”