Question

I'm logging to syslog with a syslog appender as shown below:

<appender name="SYSLOG" class="ch.qos.logback.classic.net.SyslogAppender">
        <syslogHost>localhost</syslogHost>
        <facility>LOCAL6</facility>
        <suffixPattern>app: %logger{20} %msg</suffixPattern>
    </appender>

But I've got a new requirement where I want to send some logs to the "LOCAL5" facility instead of LOCAL6. I've read the logback configuration documentation http://logback.qos.ch/manual/configuration.html but I'm still not sure how to do this.

Was it helpful?

Solution

You can use two syslog appenders one for LOCAL6 and other for LOCAL5

<appender name="SYSLOG" class="ch.qos.logback.classic.net.SyslogAppender">
        <syslogHost>localhost</syslogHost>
        <facility>LOCAL6</facility>
        <suffixPattern>app: %logger{20} %msg</suffixPattern>
    </appender>


<appender name="SYSLOG1" class="ch.qos.logback.classic.net.SyslogAppender">
        <syslogHost>localhost</syslogHost>
        <facility>LOCAL5</facility>
        <suffixPattern>app: %logger{20} %msg</suffixPattern>
    </appender>

Advantage is that you a customize the logs( some logs) using filters, pattern, logger names etc. And SyslogAppender extends UnsyncronizedAppender.

Reason being you cannot use single appender is that method facilityStringToint(String facilityStr) in class SyslogAppender.java accepts String which then compares which standard facility using equals. Example

     if ("KERN".equalsIgnoreCase(facilityStr)) {
          return SyslogConstants.LOG_KERN;
     }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top