Skip to content
Tutorials Center
My learning

Topics

Linux Command Reference ยท Packages and Services

Linux logger command

Reference for the Linux logger command: send messages to syslog or the journal from scripts, with tags, priorities, facilities and reading input from a pipe.

logger sends a message to the system log. Shell scripts use it to leave a trace that shows up beside everything else the machine logs: in journalctl, in /var/log/syslog or /var/log/messages, and on a central log server if the machine forwards its logs.

Every message has a facility (the kind of source, such as user, daemon, auth or local0 to local7), a priority (severity from emerg to debug), and an optional tag that names the program. The defaults are user.notice and a tag equal to your login name, so scripts should always set their own tag.

Terminal
logger "backup finished"
logger -t backup -p user.err "backup failed"
echo "from a pipe" | logger -t demo

Try it

logger talks to a log socket (/dev/log), which usually does not exist in the sandbox. The first example writes to standard error with -s as well, so you can see the message; the second builds a reusable log() function with the same idea.

Bash Echo the message too with -s

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Bash A log function that falls back to a file

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.

Syntax

Terminal
logger [OPTION]... [MESSAGE]...
Option Description
-t TAG Tag (program name) put in front of the message.
-p FACILITY.LEVEL Priority, such as user.notice, daemon.err or local3.info. A bare level means user.LEVEL.
-i Include the process ID of logger.
-s Also print the message to standard error.
-f FILE Log the lines of FILE.
-n SERVER, -P PORT, -T, -d Send to a remote syslog server (UDP by default, TCP with -T).
--journald Send a structured entry with fields (util-linux 2.38+).
-u SOCKET Write to a specific Unix socket.
--id=ID, --rfc5424 Set the message ID; use the newer message format.

Levels from most to least severe: emerg, alert, crit, err, warning, notice, info, debug. If no message is given, logger reads standard input and logs each line.

Returns: 0 on success, non-zero if it cannot write to the log (for example when there is no log socket).

Usage notes

  • Always set -t. Without it, entries are tagged with your user name and are hard to filter. Then journalctl -t backup finds them all.
  • Quote the message so the shell passes it as one argument; unquoted words are joined with single spaces anyway.
  • Priority filtering: syslog daemons and the journal may drop low priorities (often debug), and journalctl -p err shows only errors and worse.
  • Use local0 to local7 for your own applications so rules in rsyslog can route them to their own file.
  • A failed logger call is silent in many scripts, because the error goes to stderr. In containers there is often no syslog at all; write to stdout instead and let the runtime collect it.
  • Pipelines: mycmd 2>&1 | logger -t mycmd logs everything a command prints, line by line.
  • Do not log secrets. System logs are readable by many administrators and are often shipped elsewhere.
  • Rate limits: the journal and rsyslog may suppress bursts of repeated messages; do not use logging for high-volume data.