Commands / Monitoring and logs

Monitoring and logs

logger

Also syslog, rsyslog, write to the log

Writes a line to the system log, with a tag, facility and severity of your choice.

logger does by hand what daemons do: it hands one line to the local syslog daemon (through /dev/log), which files it and forwards it wherever its rules say. Use it to test a logging setup end to end: log a line on the device, look for it on the collector. -p facility.severity sets the PRI, -t the tag.

logger command usage

logger [-t TAG] [-p FACILITY.SEVERITY] MESSAGE

Options

-t app
the tag: the program name shown before the message
-p local0.err
facility and severity (default user.notice)
-s
also print the line on standard error

logger examples

logger -t app 'order 1001 paid'
Logs one line tagged app, as user.notice.
logger -p auth.warning -t sshd 'Failed password for root'
Logs a line as facility auth, severity warning.
for level in debug info warning err; do logger -p daemon.$level "test $level"; done
Logs one line at each of four severities, to test a filter.

Pitfalls

  • BusyBox's logger only writes to the local daemon: to reach a collector, that daemon must forward.
  • The line is filed under the local host name; a collector shows it in that host's file.

Run it on real machines

Learn it on real machines.

Every lab is a small network of real Linux machines in your browser. Start with a free account: Google or email, no card.

Open this lab