Short answer
If the machine is running systemd, use the journal (systemd-cat / logger).
A group-writable log file is almost always the weaker choice for integrity, safety, and maintenance.
Why the journal wins
| Feature | journal (systemd-cat) | Shared file |
|---|
| Concurrent writes | Socket API; atomic, non-blocking | Lines from different processes can interleave unless you add locks |
| Log integrity | Entries are timestamped, tagged with UID, GID, PID; ordinary users cannot tamper with old records | Anyone who has write rights can truncate, delete, overwrite, or symlink the file |
| Rotation / vacuum | Built-in SystemMaxUse, RuntimeMaxUse, MaxFileSec | You have to ship logrotate rules and hope nobody changes permissions |
| Disk DoS protection | Rate-limiting and quota in journald | A loop can fill the file or the whole FS |
| Search / filtering | journalctl -u your-service, journalctl _COMM=myscript _UID=1001 | grep/awk across one huge flat file |
| Remote forwarding | Can forward to syslog, another journal, or JSON stream | You have to implement it |
| Security context | SELinux/AppArmor already covers the journal directory | You have to label / setfacl the file yourself |
| Structured fields | systemd-cat -t myscript -p info MESSAGE_ID=abc123 | Not available |
Typical objections
“But users can’t read the system journal.”
True by default, but that is usually desirable: you don’t want Alice to read Bob’s log lines.
If you need read access you can:
# Add group 'myscriptlog' as journal readers
sudo groupadd -r myscriptlog
sudo setfacl -m g:myscriptlog:r /var/log/journal/*/system.journal
sudo usermod -aG myscriptlog alice bob
or use journalctl --output=short --grep=… inside the script and make the
command set-gid to a low-risk helper group.
“Not every distro has systemd.”
True for a minority of systems (BusyBox, Alpine without openrc-compat, etc.).
If you need portability call logger first (POSIX syslog) and fall back to a
file only when nothing is available:
if command -v systemd-cat &>/dev/null; then
exec > >(systemd-cat -t myscript) 2>&1
elif command -v logger &>/dev/null; then
exec > >(logger -t myscript) 2>&1
else
exec >>/var/log/myscript.log 2>&1
fi
Practical recipe
Inside your shell script, very early:
#!/usr/bin/env bash
TAG=myscript # shows up as SYSLOG_IDENTIFIER
PRIORITY=info # or debug / err / warning …
# Redirect stdout/err through systemd-cat
if command -v systemd-cat &>/dev/null; then
exec > >(systemd-cat --identifier="$TAG" --priority="$PRIORITY") \
2> >(systemd-cat --identifier="$TAG" --priority=err)
fi
Now every line you echo is in the journal with PID, UID, tty, etc.:
journalctl -t myscript # show only your script’s logs
journalctl _COMM=myscript -o cat --since=today
When a plain file is acceptable
• Single-user, throw-away scripts
• Running on a filesystem mounted with noexec,nosuid where journald isn’t available
• You need the users themselves to edit the file as part of workflow
In that case, create the file owned by root, writable by a dedicated group, and
protect it with flock:
LOG=/var/log/myscript/myscript.log
mkdir -p "$(dirname "$LOG")"
chown root:myscript "$LOG"
chmod 664 "$LOG"
exec 200>>"$LOG" # open FD 200 for appending
flock -n 200 || exit 1 # non-blocking lock; exit if already running
…but note how much boilerplate appears compared to one line of systemd-cat.
Bottom line
For multi-user scripts on a modern Linux box, writing to the journal is
safer, easier, and gives you auditing, rotation, and search “for free”.
Only fall back to a world/group-writable file when portability or a very
special workflow forces you to.