logger
Overview
The logger
command makes entries in the system log. It provides a shell command interface to the syslog system log module, allowing you to create log entries from the command line or scripts.
Syntax
logger [options] [message]
Common Options
Option | Description |
---|---|
-f file |
Log contents of file |
-i |
Log process ID |
-p priority |
Specify message priority |
-t tag |
Mark every line with specified tag |
-n server |
Write to remote syslog server |
-s |
Output to standard error as well |
-u socket |
Write to specified socket |
--id=[id] |
Enter log entry with specified ID |
Key Use Cases
- Script logging
- System monitoring
- Application debugging
- Security auditing
- Event tracking
Examples with Explanations
Example 1: Basic Logging
logger "System backup completed successfully"
Logs a simple message to syslog
Example 2: Tagged Message
logger -t BACKUP -p local0.info "Backup process started"
Logs a tagged message with priority
Example 3: Log File Contents
logger -f /var/log/myapp.log
Sends file contents to syslog
Understanding Output
Priority Levels: - emerg (0): System is unusable - alert (1): Action must be taken immediately - crit (2): Critical conditions - err (3): Error conditions - warning (4): Warning conditions - notice (5): Normal but significant - info (6): Informational - debug (7): Debug-level messages
Common Usage Patterns
Script logging:
logger -t myscript -p local0.info "Script started"
Error logging:
logger -i -t myapp -p local0.err "Error: Database connection failed"
Remote logging:
logger -n logserver.example.com -P 514 "Remote log entry"
Performance Analysis
- Minimal system impact
- Asynchronous operation
- Consider log rotation
- Monitor disk usage
- Check syslog configuration