Learn How to Test System Logging with Logger
Apr 30, 2024
Daniel Cid (@dcid)

All Linux distributions and BSD systems (FreeBSD, OpenBSD, etc) come with the logger tool installed out of the box. Logger is a very simple tool that uses the syslog() function to send (and test) logs from the command line. In its basic form, the C code looks like this for logger:



#include <syslog.h>
syslog(pri, "%s", buf);


Which sends the content from buf (which is the argument from the command line) to the syslog() function with the user supplied priority (which is the facility+level).



This is a logging test

The first step to test logger is to go to your command line terminal and execute the command:



$ logger "This is a logging test"


Which will generate a log on your log file (by default /var/log/syslog or /var/log/messages) that looks like:

May 26 04:15:22 testingserver dcid: This is a logging test


Which is the date, followed by the hostname of the server (testingserver) and the username (dcid) that called the logger command. If you are testing if your logging is working, and you see that log line, it means it worked.



Specifying the facility and level with logger

But logger is more flexible than just that. Let's say you want to send all error events to a specific log file and want to verify it is working. You can pass the facility and level (error) from logger as well:

$ logger -p daemon.error "This is a logging error test"


The other useful option available is the "-t" that allows you to replace your username with the program name (id) to show up in the log:

$ logger -t logtester -p daemon.error "This is a logging error test"


And now you should see the following on the logs:

May 26 04:24:57 testingserver logtester: This is a logging error test


And that's it. Logger is easy and useful.

Logging Guides

We love logs. In this section we will share some articles from our team to help you get better at logging.

Trunc Logging

Logging for fun and a good night of sleep.

  • Real time search
  • Google simple
  • Cheap
  • Just works
  • PCI compliance
Contact us!

Do you have an idea for an article that is not here? See something wrong? Contact us at support@noc.org

Tired of price gouging
  • Clear pricing
  • No need to guess
  • Real people
  • Real logging

Simple, Affordable, Log Management and Analysis.

14 days free trial. No credit card required.