Write to syslog from the command line

How can I write an entry into /var/log/syslog from the command line?


Solution 1:

Use the logger command.

logger Some message to write

There are several options available, including:

-i Log the process ID in each line
-f Log the contents of a specified file
-n Write to the specified remote syslog server
-p Specify a priority
-t Tag the line with a specified tag

See man 1 logger for more information on the tool.

Solution 2:

Alternatively, you can write to syslog from python:

python -c 'import syslog; syslog.syslog("Hello World")'