[PATCH] Variable $time_short.

Maxim Dounin mdounin at mdounin.ru
Fri May 28 21:55:40 UTC 2021


Hello!

On Thu, May 27, 2021 at 09:48:41PM +0300, Gena Makhomed wrote:

> On 27.05.2021 20:25, Maxim Dounin wrote:
> 
> >> Variable $time_short.
> >>
> >> Variable $time_short in form "1970/09/28 12:00:00".
> >> Added to ngx_http_core_module, ngx_http_log_module,
> >> and ngx_stream_core_module.
> 
> > You may want to be more specific about expected use cases, and why
> > existing time variables are not enough.
> 
> Main purpose of variable $time_short is usage for logging, access.log.
> 
> Existing variables $time_iso8601 and $time_local has bad readability,
> because these variables contains timezone after seconds and it has
> no space between date and time fields.
> 
> Compare readability:
> 
> 27/May/2021:21:19:12 +0300
> 27/May/2021:21:19:18 +0300
> 27/May/2021:21:19:25 +0300
> 27/May/2021:21:19:32 +0300
> 27/May/2021:21:19:43 +0300
> 
> 2021-05-27T21:19:12+03:00
> 2021-05-27T21:19:18+03:00
> 2021-05-27T21:19:25+03:00
> 2021-05-27T21:19:32+03:00
> 2021-05-27T21:19:43+03:00
> 
> 2021/05/27 21:19:12
> 2021/05/27 21:19:18
> 2021/05/27 21:19:25
> 2021/05/27 21:19:32
> 2021/05/27 21:19:43
> 
> But only proposed variable $time_short has excellent readability,
> also this variable is very short, and contains no visual garbage.

Well, if you want to improve readability and don't need a timezone 
in your logs, something like this might work instead:

    map $time_iso8601 $time {
        "~([0-9-]+)T([0-9:]+)" "$1 $2";
        volatile;
    }

I don't think that introducing additional builtin variables for 
additional data/time formats is a good idea.

-- 
Maxim Dounin
http://mdounin.ru/


More information about the nginx-devel mailing list