• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • VCS
  • Interview Questions
  • Database
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

logger Command Examples in Linux

by admin

logger command is used to log messages in the system log or syslog. You can log a messages string on the command line or provide a file as input that can contain the message to be logged.

To view the available switches for the logger command:

# logger --help

Usage:
 logger [options] [message]

Options:
 -T, --tcp             use TCP only
 -d, --udp             use UDP only
 -i, --id              log the process ID too
 -f, --file [file]     log the contents of this file
 -h, --help            display this help text and exit
 -S, --size [num]      maximum size for a single message (default 1024)
 -n, --server [name]   write to this remote syslog server
 -P, --port [port]     use this port for UDP or TCP connection
 -p, --priority [prio] mark given message with this priority
 -s, --stderr          output message to standard error as well
 -t, --tag [tag]       mark every line with this tag
 -u, --socket [socket] write to this Unix socket
 -V, --version         output version information and exit

logger command examples

1. To log the message to standard error and system logs

# logger -s "This is a test message" 

2. To log to message to the specified file

# logger -f file "This is a test message"

3. To log the message with specified priority

# logger -p 1 "This is a test message"

4. To mark every line with specified tag

# logger -t TAG "This is a test message"

5. To allow the message to start with a hyphen

# logger -- "This is a test message"

Filed Under: Linux

Some more articles you might also be interested in …

  1. betterlockscreen Command Examples in Linux
  2. flatpak: command not found
  3. telinit: command not found
  4. CentOS / RHEL 7 : sysctl kernel parameter doesn’t take effect after reboot
  5. backlight_control Command Examples in Linux
  6. a2query Command Examples in Linux
  7. “git restore” Command Examples
  8. Understanding iscsiadm Utility in CentOS / RHEL
  9. How to add words to the dictionary cracklib uses for validating passwords against known dictionary words
  10. dirb Command Examples in Linux

You May Also Like

Primary Sidebar

Recent Posts

  • glab Command Examples
  • “glab repo” Command Examples
  • “glab release” Command Examples
  • “glab pipeline” Command Examples

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright