Search code examples
linuxunixconfigurationsyslogbsd

syslog: process specific priority


I have two user processes A and B. Both use syslog using facility LOG_USER.

I want to have different threshold levels for them:

  • For A, only messages of priority ERR-and-above must be logged
  • For B, only messages of priority CRIT-and-above must be logged

I found that if I setup /etc/syslog.conf as

user.err    /var/log/messages

then messages of ERR-and-above are logged, but, from both A and B.

How can I have different minimum threshold levels for different processes?

Note: I am exploring if there is a config file based solution. Otherwise, there is another approach that works. In each process, we can use setlogmask() to install process specific priority mask.

EDIT (Nov 18): I want to use syslog and some portable solution.


Solution

  • This tutorial http://www.freebsd.org/cgi/man.cgi?query=syslog.conf&sektion=5 helped me. The following seem to work:

    # process A: log only error and above
    !A
    *.err                /var/log/messages
    
    # process B: log only critical and above
    !B
    *.critical           /var/log/messages
    
    # all processes other than A and B: log only info and above
    !-A,B
    *.info               /var/log/messages