Thursday, September 1, 2022

[SOLVED] Apache Log format timestamp unable to get timezone offset

Issue

LogFormat "{ \
        \"@timestamp\": \"%{%Y-%m-%dT%H:%M:%S%Z}t\", \
        \"@version\": \"1\", \
        \"clientip\": \"%a\", \
        \"status\": %>s, \
        \"bytes\": %B, \
        \"request\": \"%U%q\", \
        \"referer\": \"%{Referer}i\", \
        \"useragent\": \"%{User-agent}i\" \
        }" combinedJSON

Outputs name of timestamp instead of +0400 for example:

"@timestamp": "2016-08-29T16:50:37 Pacific Daylight Time", 

Should be:

"@timestamp": "2016-08-29T16:50:37 -0700",  

Is there no way to extract the timezone offset instead of the timezone name?


Solution

On linux'es strftime() the offset is lowercase 'z'. You used big 'Z' which is the timezone name / abbreviation.

(mod_log_config just passes the format to the systems strftime so it cannot really document the values)



Answered By - covener
Answer Checked By - Willingham (WPSolving Volunteer)