rsyslog Configuration and Filtering
What you'll learn: How to configure rsyslog to intelligently route, filter, and process system logs based on facility, severity, and content patterns.
The Core Idea
Think of rsyslog as a smart mail sorting facility. Just as postal workers route packages to different destinations based on addresses and priorities, rsyslog examines incoming log messages and directs them to appropriate files, remote servers, or other destinations based on configurable rules. This filtering prevents log sprawl and ensures critical security events land where you need them.
Configuration Basics
The main configuration file is /etc/rsyslog.conf, supplemented by files in /etc/rsyslog.d/. Rsyslog uses a rule-based syntax:
Selector format: facility.severity action
For example:
auth.* /var/log/auth.log– Send all authentication logs to auth.log*.emerg *– Broadcast emergency messages to all logged-in userskern.crit @192.168.1.10– Forward critical kernel logs to remote syslog server
Filtering Rules
You can filter by:
- Facility and priority:
mail.info,daemon.err,*.=debug(exact match) - Property-based:
if $programname == 'sshd' then /var/log/ssh.log - Content matching:
if $msg contains 'failed password' then /var/log/security/auth-failures.log
Templates
Templates format output. Define them before use:
template(name="SecFormat" type="string" string="%timegenerated% %hostname% %syslogtag% %msg%\n")
auth.* /var/log/auth.log;SecFormat
You can also discard matched messages with stop to prevent duplication or use ~ to discard after processing.
Key Takeaway: Rsyslog filtering and templates transform raw log streams into organized, actionable security intelligence by routing messages based on facility, severity, program name, or content patterns—essential for detecting threats without drowning in noise.