fbpx

Solutions

How to filter log to a separate file

by ,


We have by far the largest RPM repository with NGINX module packages and VMODs for Varnish. If you want to install NGINX, Varnish, and lots of useful performance/security software with smooth yum upgrades for production use, this is the repository for you.
Active subscription is required.

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

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>

This site uses Akismet to reduce spam. Learn how your comment data is processed.