Setting Output Data Timezone with --tz but without %z
Hi,
I'm using goaccess 1.9.3. My web server logs use UTC as the timezone for the date and time, however the timezone is not specified in the log itself. For example, a line of my log looks like
2025-02-26 00:41:54 <app name> GET ...
I'd like my goaccess report to be given in Pacific time zone. For this I thought I could run goaccess with the following parameters
goaccess <log file> --time-format %H:%M:%S --date-format %Y-%m-%d --log-format "%d %t %^ %m %U %^ %^ %^ %h %u %^ %R %^ %s %^ %^ %b %^ %L" --tz=America/Los_Angeles -o tmp.csv
However when I run the command above, I'm still getting reports in UTC time.
For example, in the general panel I see the date the report was generated as 2/25/2025 17:08, which is the correct time I generated the report since I'm in Pacific time. But when I view the the other panels, the visitors panel shows 2/26/2025 and the visit_time panel shows 00, which is the corresponding time of the UTC logs, so they weren't converted.
Am I understanding the purpose of the --tz argument correctly and am I using it correctly? If not is there a way to achieve what I want?
Thank you
Good catch! Right now, it expects a %z in the time format for the timezone to work (strptime). We could add a fallback so that if %z isn’t provided but --tz is, it assumes to UTC. What do you think?
Hi @allinurl,
Thanks for the quick response. I think that is a reasonable way to handle it and would cover my case.
There could be other cases where a users logs don't specify the time zone but default to the servers local time. Then the user wants to convert to a different time zone from the servers local time. If you took the approach you mentioned then goaccess would assume the wrong time zone of UTC and the conversion would be incorrect.
I'm not sure how common that would be, if at all. I'd think most servers would specify the time zone if it wasn't UTC so the user could use %z in the --time-format parameter for their case.
Thanks
So after double checking this, it appears that the time will be converted to the specified timezone, regardless of whether %z is used. However, in your case, when passing America/Los_Angeles, the time didn't change because your system is already set to UTC. To resolve this, you need to specify TZ=UTC before running GoAccess, so it can correctly assume the input data is in UTC.
e.g.,
$ TZ=UTC ./goaccess access.log --log-format='%v:%^ %h %^[%d:%t %^] "%r" %s %b "%R" "%u" %D' --date-format=%d/%b/%Y --time-format=%T --date-spec=min
here's an example:
Let me know if that solves the issue for you.
you need to specify TZ=UTC before running GoAccess, so it can correctly assume the input data is in UTC.
I'm just stopping by here to confirm that this solution does indeed work. Can we add a note to the documentation of the --tz=<timezone> option about this?
EDIT: Actually, I'm not sure it fully works. While it fixed the "Time Distribution" graph for me, the "Unique visitors per day" graph looks exactly the same. Here's the command I used:
TZ=UTC gzcat logs/*/*.gz | goaccess -a -o html --log-format cloudfront --geoip-database GeoLite2-Country.mmdb --geoip-database GeoLite2-ASN.mmdb --hide-referrer example.com --hide-referrer www.example.com --tz=US/Pacific
@pencil can you post a few lines from your access logs so I can try to replicate this on my end with the exact same data? Thanks