can a map + regex be used to generate variables for YYYY-MM-DD-HH?
Francis Daly
francis at daoine.org
Fri Oct 24 07:21:15 UTC 2014
On Thu, Oct 23, 2014 at 07:17:20PM -0400, newnovice wrote:
Hi there,
> Where I am going with this is - I want to write error & access - logs out
> with the 'YYYY-MM-DD-HH' suffix. So i need these variables.
I'm not aware that error_log takes variables.
You may be happier moving the log files to time-named versions and then
signalling nginx to re-open the log files, every hour.
http://nginx.org/en/docs/control.html
> The 'if' statement is not allowed outside the server{} - I am at a loss due
> to this.
if() doesn't work for you inside location{}, and it is not allowed
outside server{}. What happens if you put it inside server{} but outside
location{}?
> Please con you show me some examples of how to set these variables
> with a map regex?
Untested, but given that you already have
if ($time_iso8601 ~ "^(\d{4})-(\d{2})-(\d{2})") {
set $year $1;
set $month $2;
set $day $3;
}
then I would expect that something like
map $time_iso8601 $year {
"~^(?P<one>\d{4})-(\d{2})-(\d{2})" $one;
}
would do the right thing.
> I can have 4 seoerate maps to get it done - doesn't matter.
If you want to use map for this, then you would need multiple ones. But
I suspect that variable-in-log-file-name is not what you want.
Good luck with it,
f
--
Francis Daly francis at daoine.org
More information about the nginx
mailing list