Skip to content

Setting Output Data Timezone with --tz but without %z #2796

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
connor-dawson opened this issue Feb 26, 2025 · 5 comments
Open

Setting Output Data Timezone with --tz but without %z #2796

connor-dawson opened this issue Feb 26, 2025 · 5 comments

Comments

@connor-dawson
Copy link

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

@allinurl
Copy link
Owner

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?

@connor-dawson
Copy link
Author

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

@allinurl
Copy link
Owner

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:

Image

Let me know if that solves the issue for you.

@allinurl allinurl changed the title Setting Output Data Timezone Setting Output Data Timezone with --tz but without %z Mar 22, 2025
@pencil
Copy link

pencil commented May 15, 2025

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

@allinurl
Copy link
Owner

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants