Operations 7 min read

Mastering the Linux logger Command to Write Custom Entries to System Logs

This guide explains how to use the Linux logger utility to manually add, tag, prioritize, and forward messages to local or remote syslog files, including examples for quoting, reading from files, setting process IDs, and limiting message size.

ITPUB
ITPUB
ITPUB
Mastering the Linux logger Command to Write Custom Entries to System Logs

The logger utility (provided by the util-linux package) writes custom entries to the system log, which is typically stored in /var/log/syslog on Debian‑based distributions or /var/log/messages on RPM‑based systems.

Basic Usage

Write a simple message: logger "Welcome to OSTechNix" Verify the entry with:

tail -f /var/log/syslog

Quoting and Multiple Lines

Wrap the message in single or double quotes to preserve spaces and special characters:

logger "Welcome to OSTechNix blog"
logger 'Howdy, Welcome to OSTechNix blog'

Including the Process ID

Use -i to prepend the logger process’s PID to each line:

logger -i "Message with PID"

Tagging Messages

By default the tag is the current user name. Override it with -t (optionally combined with -i):

logger -i -t mytag "Tagged message"

Logging From a File

Write the contents of a file to the log with -f. Empty lines can be omitted with -e:

# Create a test file
 echo "This is a test file" > file.txt
# Log the file contents
 logger -f file.txt
# Omit empty lines
 logger -e -f file.txt

Setting Priority

Specify a syslog priority using --priority (or -p for short). The default is user.notice:

logger "Important notice" --priority user.warning

Sending to a Remote Syslog Server

Forward messages to a remote syslog daemon with --server (or -n) and --port (or -p). The standard syslog port is 514:

logger "Remote test" --server remote-host.example.com --port 514
logger "Remote test" -n remote-host.example.com -p 514

Limiting Message Size

Control the maximum length of a log entry with --size. The built‑in default is 1 KiB. Example truncates a long string to 5 bytes: logger --size 5 abcdefghijklmnopqrswxyz Check the truncated output with tail -f /var/log/syslog.

Reference

All options are documented in the manual page:

man logger
Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

loggingcommand-lineloggersyslogsystem-administration
ITPUB
Written by

ITPUB

Official ITPUB account sharing technical insights, community news, and exciting events.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.