How to suppress StreamBase operator and adapter log messages using logback

How to suppress StreamBase operator and adapter log messages using logback

book

Article ID: KB0083827

calendar_today

Updated On:

Products Versions
TIBCO Streaming -

Description

Sometimes an operator's log messages need to be completely dropped and not logged. An example of this is when an operator is used to to introduce an error state intentionally and the log messages are frequent, expected, and unhelpful.

Issue/Introduction

Example logback configuration for not logging a specific operator's messages

Resolution

Using logback, provide a logback XML configuration file and reference it in the sbd.sbconf as:
    <java-vm>
        <sysproperty name="logback.configurationFile" value="newlogback.xml"/>
    </java-vm>

(You may name the logback XML file anything that makes sense for your project.)

In the logback configuration file, provide a logger for the operator with additivity turned off, identified by simple name, and an appender which does nothing. For example (newlogback.xml):
<?xml version="1.0" encoding="UTF-8"?>

<configuration scan="true"> <!-- debug="true" -->
  <appender name="RootConsoleAppender"
            class="ch.qos.logback.core.ConsoleAppender">
    <encoder>
      <pattern>%d{yyyy-MM-dd HH:mm:ss.SSSZ} [%thread] %-5level %logger{36} - %msg%n</pattern>
    </encoder>
  </appender>
  <appender name="NoOpAppender" class="ch.qos.logback.core.helpers.NOPAppender"/>

  <logger name="TestReader" level="OFF" additivity="false">
      <appender-ref ref="NoOpAppender"/>
  </logger>
  <root>
    <level value="Info"/>
    <appender-ref ref="RootConsoleAppender"/>
  </root>
</configuration>
The operator is called "TestReader" in the StreamBase application.

Turning off additivity makes sure the message is handled by only that single logger and no others. In this configuration, setting the log level to "OFF" is redundant.

The optional configuration setting, debug="true", is used to provide additional messages at startup to troubleshoot logging configuration problems. This is commented out in this example. To use it, change the configuration line to be:
  <configuration scan="true" debug="true">