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

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • 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. How to Disable Daylight Savings Time (DST), and Modify the Timezone on Linux
  2. Linux OS Service ‘syslog’
  3. Connection using SSH to a Host Not in DNS/hosts Stalls for Some Time at Connection Initiation
  4. How to Enable Disk Quotas on an XFS File System
  5. What are different Samba Server Types
  6. Linux OS Service ‘ldap’
  7. How to manage File and Directory Permissions/Ownerships in Linux
  8. wc Command Examples in Linux
  9. CentOS / RHEL : How to set up chroot jail SFTP
  10. How To Check World Wide Port Names (WWPN) of Tape Drives Attached to Linux host

You May Also Like

Primary Sidebar

Recent Posts

  • vgextend Command Examples in Linux
  • setpci command – configure PCI device
  • db_load command – generate db database
  • bsdtar command – Read and write tape archive files

© 2022 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright