Search code examples
javamysqllogbackjboss6.x

Exclude default logback file


My team is developing a telecom realtime application with high calls per second rate. We are using logback to filter log based on a key-value match (traffic live values, like Calling Party, and so on). The filtered log file is correctly created, once verified the match from live values and db values, but we would get rid of default file which is filled with logs when there is no match. It might happen that a traffic node needs to be monitored for a while before a key-value match takes place, so in the meantime the default could indefinitely increase in size and cause problems to performance and stability of node itself. What should I do in my logback.xml to avoid generation of default log file? Is it possible? Any other option to achieve same result?

logback.xml

<?xml version="1.0" encoding="UTF-8"?>

<property scope="context" name="LOG_LEVEL" value="INFO" />

<appender name="SIFT_LOGGER" class="ch.qos.logback.classic.sift.SiftingAppender">
    <discriminator class="com.ericsson.jee.ngin.services.log.ServiceKeyDiscriminator">

    </discriminator>
    <sift>

        <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">

            <prudent>true</prudent>
            <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy">                   
                <fileNamePattern>/var/log/tit/logback_${serviceKey}_%d{yyyy-MM-dd}_%i.log</fileNamePattern>
                <maxFileSize>1MB</maxFileSize>    
                <maxHistory>10</maxHistory>
                <totalSizeCap>2GB</totalSizeCap>
            </rollingPolicy>

            <filter class="ch.qos.logback.classic.filter.LevelFilter">
                <level>${LOG_LEVEL}</level>
                <onMatch>ACCEPT</onMatch>
                <onMismatch>DENY</onMismatch>
            </filter>

            <!-- encoders are by default assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder -->
            <encoder>
                <pattern> %d{yyyy-MM-dd HH:mm:ss.SSSZ} [%thread]  %-5level %logger{36} %msg%n</pattern>
            </encoder>
        </appender> 
    </sift>
</appender> 

<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <!-- encoders are by default assigned the type ch.qos.logback.classic.encoder.PatternLayoutEncoder -->

    <encoder>
        <pattern> %d{yyyy-MM-dd HH:mm:ss.SSSZ} [%thread] %-5level %logger{36} %msg%n</pattern>
    </encoder>

</appender> 

<turboFilter class="ch.qos.logback.classic.turbo.DynamicThresholdFilter">
    <key>serviceKey</key>
    <defaultThreshold>DEBUG</defaultThreshold>
    <onHigherOrEqual>ACCEPT</onHigherOrEqual>
    <onLower>ACCEPT</onLower>       

</turboFilter>

<root level="DEBUG">
    <appender-ref ref="SIFT_LOGGER" />              
    <appender-ref ref="STDOUT" />
</root>

ATTACHMENTS: FILTERED LOGBACK CLASS

The provided FL class is only working for a SK which has a java Discriminator in FL module.


Solution

  • Just to notify to @glitch (and all others interested) the happy conclusion of this issue: I have managed to make the tag expression working was this:

    <expression>mdc.get("servicekey") == null</expression>
    

    Thanks to this expression, I have got the wanted behavior: the default file "IS_UNDEFINED is not generated when the key doesn't match with the runtime traffic values.

    The reason is because the type of Event in JaninoEventEvaluator is LoggingEvent that has a reserve object "mdc" (the type is Map).

    Regards, Pierluigi