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.
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/syslogQuoting 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.txtSetting Priority
Specify a syslog priority using --priority (or -p for short). The default is user.notice:
logger "Important notice" --priority user.warningSending 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 514Limiting 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 loggerSigned-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
ITPUB
Official ITPUB account sharing technical insights, community news, and exciting events.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
