Linux System Logging and Log Management
Posted on June 1, 2024 (Last modified on June 8, 2024) • 1 min read • 207 wordsLearn about system logging in Linux, including configuring and managing logs using rsyslog, journald, and log rotation with logrotate.
Effective log management is crucial for monitoring and maintaining system health. This guide covers configuring and managing logs in Linux using rsyslog, journald, and log rotation with logrotate.
Configure rsyslog for system logging.
sudo vim /etc/rsyslog.confRestart rsyslog to apply changes.
sudo systemctl restart rsyslogUse journalctl to view system logs.
sudo journalctlFilter logs by time.
sudo journalctl --since "2024-01-01" --until "2024-01-31"Edit the logrotate configuration file.
sudo vim /etc/logrotate.confRotate logs weekly and keep 4 weeks of logs.
/var/log/syslog {
weekly
rotate 4
compress
missingok
notifempty
create 0640 root utmp
sharedscripts
postrotate
/usr/lib/rsyslog/rsyslog-rotate
endscript
}Force log rotation manually.
sudo logrotate -f /etc/logrotate.confCreate a custom log file and configure rsyslog to write to it.
sudo vim /etc/rsyslog.d/custom.confAdd the following configuration.
if $programname == 'myapp' then /var/log/myapp.log
& stopRestart rsyslog to apply changes.
sudo systemctl restart rsyslogEffective log management is essential for system monitoring and maintenance. Practice configuring rsyslog and journald, and managing log rotation with logrotate to maintain a healthy logging system in Linux.