I think syslog is really a good choice for service.
Besides syslog, is there any other file logging best practice ?
Is writing file to /tmp
or /var/log
directly appropriate?
I think syslog is really a good choice for service.
Besides syslog, is there any other file logging best practice ?
Is writing file to /tmp
or /var/log
directly appropriate?
Read logging best practice. Questions with risk to attract too opinionated answers will be closed.
Is writing file to
/tmp
or/var/log
directlyavailableappropriate?
A common set of permissions for /tmp
:
drwxrwxrwt root root /tmp
So, available, yes, but appropriate, no, not for logs. /tmp
is often purged on reboot.
A common set of permissions for /var/log
:
drwxr-xr-x. root root /var/log
So, it's usually only root
processes that can create files there. Other processes need to have a logfile installed in advance and logrotate
d - or having a subdirectory with permissions allowing the process owner to create files in it.
If your system uses journald, it may be more appropriate to make use of that instead of creating your own log files as described in Linux Logging with Systemd.
Edit: Since the original question was partly about programming languages before it was edited, I'll leave this note here:
Whether to use syslog or not doesn't have anything to do with the choice of language. If you have a syslog service, it can be used by programs written in any language.
I found that after I create a fold in /var/log
, such as /var/log/myprocess/
. Notice that /var/log
belongs to root
, and I use chown
so /var/log/myprocess/
belongs to me.
So my process can create and write files directly in /var/log/myprocess/
, such as /var/log/myprocess/process-log-2019-08-15.log
.