Is it possible to use local time in logfile instead of UTC on Android?

My knowledge on Linux is limited, so please forgive me if this is something obvious. When running Syncthing with -logflags=3, both date and time are written to the logfile. The problem is that they follow the UTC time, not the local time, which makes things difficult when you need to compare the logs between Linux and Windows devices (since the latter use local time instead).

Is there a simple way to make Syncthing use local time instead of UTC in logfile?

Syncthing uses the system time zone, like any other program.

% date +%Z
CEST
% syncthing -logflags 3
[start] 2021/08/08 14:26:21 INFO: syncthing v1.18.1-rc.3.dev.5.g37d0ba16.dirty "Fermium Flea" (go1.17beta1 darwin-arm64) jb@ses.kastelo.net 2021-08-01 10:30:20 UTC [purego, stnoupgrade]
...
% TZ=US/Eastern syncthing -logflags 3
[start] 2021/08/08 08:26:27 INFO: syncthing v1.18.1-rc.3.dev.5.g37d0ba16.dirty "Fermium Flea" (go1.17beta1 darwin-arm64) jb@ses.kastelo.net 2021-08-01 10:30:20 UTC [purego, stnoupgrade]
...

You might UTC when you don’t expect it if your system doesn’t have a time zone database, though.

Yeah, so date +%Z does show the correct time zone. However, Syncthing still uses UTC in the log, even if I start it with the TZ variable set to something else.

What I find strange is that if I do TZ=UTC1 date, then the output reflects the changed TZ variable. However, if I do TZ=UTC1 syncthing -logflags=3, the log still uses just UTC (as if it was TZ=UTC0).

Using named time zones like US/Eastern does nothing too :pensive:.

So maybe check that you have a valid time zone database installed. (“UTC1” and “UTC0” are also not things recognized by my systems, both instead being parsed as just “UTC”.) That date echoes your time zone doesn’t mean much.

$ TZ=trololol date
Sun Aug  8 14:35:17 trololol 2021

(That’s UTC, because the time zone trololol doesn’t actually exist in the database.)

I didn’t mean the name, but rather the time being changed, e.g.

$ TZ=UTC0 date
Sun Aug  8 14:40:12 UTC 2021
$ TZ=UTC1 date
Sun Aug  8 13:40:59 UTC 2021
$ TZ=UTC-5 date
Sun Aug  8 19:40:39 UTC 2021

The database is there and works though, e.g.

$ TZ=America/Montevideo date
Sun Aug  8 11:42:19 -03 2021

However, I think that I have found the culprit. I have the problem on Android, but for some reason I believed it to be a general Linux issue (hence the general support category, which I’m going to change after this post).

In reality, the problem seems to be specifically time: time.Local is always UTC on Android · Issue #20455 · golang/go · GitHub, which is basically about Golang always using UTC when the OS is Android, completely ignoring the TZ variable. I have tried to fiddle around with the Go source timezone files related to Android trying to perhaps hardcode my own timezone instead of UTC, but I couldn’t get it to work in the actual Syncthing binary, which still displays the time in UTC.

Yeah, please don’t treat android === linux, android is android, despite being based on the linux kernel. For most intents and purposes it’s its own thing.

Apparently TZ is a GNU thing, i.e. even if that issue gets fixed, it won’t consider that but the android settings.

2 Likes

It’s fascinating that date a) apparently does something with those timezones yet prints them all as “UTC” and b) uses the wrong adjustment direction, i.e. you say “UTC-5” but it in fact returns UTC+5. I have no idea what’s going on, and no real desire to either.

:facepalm: but the above isn’t limited to that, my Mac does the same.

I got those values initially from an answer on stackoverflow, but the real source is https://gnu.org/software/libc/manual/html_node/TZ-Variable.html. Basically, negative numbers mean going to the east, positive ones going to the west. date is doing its job correctly here.

Yeah, my main goal here is not have TZ working, just to somehow make Syncthing use the local time instead of UTC. As long as the Go issue stands, there is no way to override the time zone value used in the logfile, right?

1 Like

Right,

The offset specifies the time value you must add to the local time to get a Coordinated Universal Time value.

So it’s not a time zone name as I thought, just a hack to describe a time zone with offset while giving it a name, like “EST+5” saying that EST+5 = UTC.

1 Like

I added the workaround from the linked issue: lib/syncthing: Set system timezone on android by imsodin · Pull Request #7878 · syncthing/syncthing · GitHub

2 Likes

Wow. Thanks a lot for this. It was always a major pain when I had to check for something in the logs from my Android devices and always remember to recalculate the time to my time zone.

I have cherry picked the commit, and I can confirm that it does what it is supposed to :slight_smile:.

1 Like

Thanks, @imsodin , definitely useful :slight_smile:

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.