Site icon GetPageSpeed

How to filter log to a separate file

Operating System and Software

  • CentOS 6
  • CentOS 7
  • Rocky Linux 8

Problem

  • How to filter out the keyword as XXX or YYY from messages to another file such as /var/log/test.log

How to Fix

  • Create a file under /etc/rsyslog.d for example: 35-test.conf and add below content.
if $msg contains 'XXX' or $msg contains 'YYY' then /var/log/test.log
& ~

Then restart rsyslog service.

  • on RHEL6
    # service rsyslog restart
  • on CentOS 7 or Rocky Linux 8
    # systemctl restart rsyslog.service
Exit mobile version