Lead Image © Andrey Prokhorov, Fotolia.com
Adding your own information to syslog
Custom Log
HPC administrators periodically look through the system logs in /var/log, searching for errors or other interesting information. Although it is very nice that the logs are centralized and that admins have tools that use these logs to provide notifications, they are not easy to process and understand. Wouldn't it be nice to be able to put your own information into the system log (/var/log/syslog) so you can parse it for your messages with common tools such as grep? Of course, Linux has a tool for that: logger.
The system log is a central location for all system messages and would be a convenient location for storing your own messages. Any automatic log processing tool will catch these messages, but you can easily set up a simple grep to capture the messages you publish to syslog either manually or in scripts. This capability allows you to use all kinds of logging as part of your system administration, including adding logger entries into the system log. The logger entries can be done manually or incorporated into scripts.
Introduction to Logger
All of the examples in this article are from a rather dated Ubuntu 20.04 system, although logger works the same way on current distributions. The basic syntax to write a simple message to the system log is pretty easy:
$ logger "Just a test"
The entry in syslog will include a timestamp indicating when the message was written to the system log, the name of the system, the user who wrote the message or the tag used to write the message, and, after a colon, the message itself:
... Jun 28 12:24:55 laytonjb-Nitro-AN515-55 laytonjb: Just a test ...
This capability is really simple but very powerful. You can create the message as part of a script (e.g., a Bash
...Buy this article as PDF
(incl. VAT)
Buy ADMIN Magazine
Subscribe to our ADMIN Newsletters
Subscribe to our Linux Newsletters
Find Linux and Open Source Jobs
Most Popular
Support Our Work
ADMIN content is made possible with support from readers like you. Please consider contributing when you've found an article to be beneficial.

