System and processes
The logger command
Writes a message to the system log (syslog) from a script.
Most useful options
-t, --tag ETIQUETATags the message. By default it is the name of the user logged in on the terminal-p, --priority PRIORIDADPriority, optionally with a facility: user.err or err. Defaults to user.notice-s, --stderrAlso shows the message on standard error-f, --file ARCHIVOLogs the contents of a file. It cannot be combined with a message on the command line-e, --skip-emptyIgnores empty lines when processing files-n, --server SERVIDORSends the message to a remote syslog server instead of the local logCopy-ready examples
$ logger -t mitest holawrites the message hola with the tag mitest. It is the first test to see that it arrives.$ logger -t backup -p user.warning 'copia incompleta'logs a warning with warning priority, to review later.$ echo 'copia terminada' | logger -t backupwith no message on the command line, logger logs what arrives on standard input.$ journalctl -t mitest -n 5reads the last five entries with that tag, to confirm they reached the journal.You can try them in the browser terminal: it does not touch your computer.
Common errors
| Message | Cause | Fix |
|---|---|---|
| logger: unknown priority name: foo | The priority name does not exist. You misspelled the priority or used one logger does not know. | Use a valid name such as err, warning, notice or info, with or without a facility: user.warning. |
| logger: unknown facility name: foo | The part before the dot is not a valid facility. With -p, the format is facility.priority. | Use a known facility, such as user or local0, and the priority after the dot: user.err. |
Typical mistakes
- Without -t, the tag is your user name and you will not know which script wrote the message. Always put -t with the script name.
- Writing with logger does not prove the message arrived: confirm it by reading the log with journalctl.
- With -n the message goes over the network to another server and does not appear in your local log.
Differences from similar commands
- echo: writes to the terminal output. logger sends the message to the system log.
- journalctl: reads the log. logger is the command that writes to it from the terminal or a script.
- dmesg: shows kernel messages. logger writes messages from user programs.
Security
What you log stays readable for anyone who can read the log. Do not put passwords, tokens or personal data in a message.
Related commands
FAQ
Which priority does logger use if I do not give one?
user.notice, the default priority. Use -p when you want to mark a message as a warning or an error.
How do I log several lines from a file?
With -f file, each line of the file is logged as a message. With -e, empty lines are skipped. -f cannot be combined with a message at the same time.
How do I read what logger wrote?
With journalctl -t tag, which filters entries by the tag you used with -t.
Learn to actually use it
The basic Linux course takes you from zero to console fluency with 24 self-grading lessons.
Start the free course