Excluding only one level of Log4j Logger

I am using Log4j in an application in which I am also using Axis2 and Jetty webserver.

I configured my Log4J properties file to exclude these classes from logging when debugging priority. But when I did that, other priority messages also began to be excluded from the main registrar.

Is there a way I can tell Log4j that I just want to log INFO logs from these classes when logging debug logs from my classes?

Here's what I did:

#Jetty Server and Axis2
log4j.category.org.apache.axiom=DEBUG
log4j.additivity.org.apache.axiom=false
log4j.category.org.apache.axis2=DEBUG
log4j.additivity.org.apache.axis2=false

################# MAIN LOGGER #################
log4j.rootCategory=DEBUG, mainLogger

#File configuration

      

But since I said this configuration also excludes INFO messages from the main logger.

+3


source to share


3 answers


No, set the root level to DEBUG and

log4j.category.org.apache.axiom=INFO
log4j.category.org.apache.axis2=INFO

      

Also, don't set additivity to false

.



When you start from scratch, you can immediately use the more modern XML format. There it would be like this:

<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/">

<appender name="FILE" class="org.apache.log4j.RollingFileAppender"> 
...
</appender> 

<category name="com.apache.axiom">
    <priority value="INFO" />
</category>

<root> 
    <priority value ="DEBUG" /> 
    <appender-ref ref="FILE" /> 
</root>

</log4j:configuration>

      

+4


source


Set rootCategory to a value INFO

, set a suitable registrar of your classes (for example org.myemployer.myapp

) toDEBUG



0


source


With this you can set the log level:

    import org.apache.log4j.Level;

    public static Logger logger = null;

    logger.setLevel(Level.DEBUG);

      

and

 Logger.getRootLogger().setLevel(Level.INFO);

      

-1


source







All Articles