How do I change the log file in a manner that survives upgrades?

As far as I can tell, Syncthing does not have an option for where it writs its logs (it just spews them to standard output and standard error). Since I run it through systemd, I can edit /etc/systemd/system/multi-user.target.wants/syncthing@myusername to add

StandardOutput=/var/log/syncthing.log
StandardError=/var/log/syncthing.log

but that file is a symlink to /lib/systemd/system/syncthing@.service, which gets wiped without notice every time the syncthing package updates. I’ve read there’s an oddity in systemd in which these files must be symlinks, but even if that wasn’t the case, if I detach it, I won’t benefit from changes to the defaults as they come in (I tested this; apt did not warn me before overwriting the file, which makes sense since configuration files should not exist in /lib).

Is there a way to specify a log file or do I need to create a feature request? Alternatively, is there a way to specify additional configurations in systemd that is additive to that symlink?

Have a look at the systemctl edit subcommand. See for example this answer for a short explanation: Modify systemd unit file without altering upstream unit file - Server Fault

If I remember correctly, with the standard service files for systemd distributed with Syncthing, the output should be going to the journal. Check out the journalctl command to work with that.

1 Like

Please check https://docs.syncthing.net/users/syncthing.html#cmdoption-logfile if you want to do it via Syncthing itself. There is also the undocumented --logfile=default switch, which saves the logfile in the Syncthing’s home folder, rotating between four files.

Okay, I have combined the answers from @acolomb & @tomasz86 to create an override by running sudo systemctl edit syncthing@adamhotep.service and adding this stanza:

[Service]
ExecStart=
ExecStart=/usr/bin/syncthing serve --no-browser --no-restart --logflags=11 --logfile=default --log-max-size=2097152 --log-max-old-files=5

This appears to work. I had to guess that the units were bytes. However, it does now need root privileges to run (though it does still properly propagate files as my user).

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