Create different logs based on logging level in log4j

I am trying to create “different” applications at different levels, but so far I have not been able to find a way to isolate the logging levels ....

<category name="com.sample" additivity="false">
    <priority value="INFO" />
    <appender-ref ref="AllAsync"/> 
    <appender-ref ref="ConsoleAppender"/> 
  </category>

I need to be able to land only for INFO priority logs that need to be added. Since registering the INFO level also adds to the registered DEBUG registrars ... this does not help me.

Another thing is that for the "same" package I could not define different logging applications:

     <category name="com.sample" additivity="false">
            <priority value="INFO" />
            <appender-ref ref="AllAsync"/> 
            <appender-ref ref="ConsoleAppender"/> 
          </category>

     <category name="com.sample" additivity="false">
        <priority value="DEBUG" />
        <appender-ref ref="AllAsync"/> 
        <appender-ref ref="ConsoleAppender"/> 
      </category>

Here I get errors something like this:

log4j:ERROR Attempted to append to closed appender named [AllAsync].
log4j:ERROR Attempted to append to closed appender named [ConsoleAppender].
log4j:ERROR Attempted to append to closed appender named [ConsoleAppender].
log4j:ERROR Attempted to append to closed appender named [ConsoleAppender].
+5
source share
1 answer

You can filter using the exact log level using LevelMatchFilter according to log4j Faq and wiki.

 <filter class="org.apache.log4j.varia.LevelMatchFilter">
         <param name="LevelToMatch" value="info"/> 
         <param name="AcceptOnMatch" value="true"/>  
 </filter>

.

+2

All Articles