The logger
command is used to add messages to the system log, which is also known as the syslog. It is a useful tool for system administrators who need to keep track of various system events, such as system startups, shutdowns, and other system-related activities.
Overview
The logger
command is used to add messages to the system log, which can be accessed using the syslog
command. The syntax for the logger
command is as follows:
logger [options] [message]
Here, the options
are used to modify the behavior of the logger
command, while the message
is the text that will be added to the system log. If no message
is specified, then the logger
command will read from standard input.
Examples
logger "System shutdown initiated"
The above command will add the message “System shutdown initiated” to the system log.
echo "System startup initiated" | logger
The above command will read the message “System startup initiated” from standard input and add it to the system log.
logger -p user.info "User login successful"
The above command will add the message “User login successful” to the system log with the priority set to “user.info”.
Options
Here are the available options for the logger
command:
Option | Description |
---|---|
-p , --priority |
Sets the priority of the message. The priority can be specified using the facility.level notation, where facility is one of the following: user, local0, local1, local2, local3, local4, local5, local6, local7. The level can be one of the following: emerg, alert, crit, err, warning, notice, info, debug. |
-t , --tag |
Sets the tag for the message. By default, the tag is set to the name of the command that was used to add the message to the system log. |
-u , --socket |
Sends the message to the specified socket instead of the default /dev/log . |
-s , --stderr |
Sends the message to standard error instead of the system log. |
-h , --help |
Displays the help message and exits. |
-v , --version |
Displays the version information and exits. |
Troubleshooting Tips
If you are having trouble adding messages to the system log using the logger
command, here are some troubleshooting tips:
- Ensure that the syslog daemon is running on your system.
- Check the permissions of the
/dev/log
socket. The user running thelogger
command must have write access to this socket. - Verify that the message is being added to the correct facility and level. Use the
-p
option to set the priority of the message.
Notes
- The
logger
command is typically used in shell scripts to add messages to the system log. - The system log can be viewed using the
syslog
command or by examining the contents of the/var/log/syslog
file.