My log4j.xml
:
<appender name="B2BAPP" class="org.apache.log4j.RollingFileAppender">
<param name="File" value="/LOGS/SAM/B2B_VJ.log"/>
<param name="Threshold" value="ERROR"/>
<param name="MaxFileSize" value="10000KB"/>
<param name="MaxBackupIndex" value="10"/>
<param name="Append" value="false"/>
<layout class="org.apache.log4j.PatternLayout">
<param name="ConversionPattern" value="%d{dd MMM yyyy HH:mm:ss,SSS} %5p [%c:%L] %m%n"/>
</layout>
</appender>
<logger name="com.sas">
<priority value="DEBUG"/>
<appender-ref ref="B2BAPP"/>
</logger>
I would like to understand the behaviour of priority value="DEBUG" and param name="Threshold" value="DEBUG".
In my logger (com.sas
) I have set the priority value "DEBUG" and appender of this logger is "B2BAPP" and in "B2BAPP" I have defined "Threshold" as "ERROR".
So log level for "com.sas" would be set to "DEBUG" or "ERROR"?
Cases :
priority value="DEBUG" and param name="Threshold" value="ERROR"
priority value="ERROR" and param name="Threshold" value="DEBUG"
What would be the output of the above cases? How does it work?
The
Logger
component accepts logging instructions (logger.debug()
,logger.error()
etc calls) and sends them to appropriate destinations to theAppender
s.You can set a "priority" on the
Logger
and instruct it to accept only logging instructions of a certain level. The levels are (in ascending importance order): TRACE, DEBUG, INFO, WARN, ERROR and FATAL.A configuration like this:
instructs the
com.sas
logger to only accept levels with a level of importance of WARN or higher (i.e. WARN, ERROR and FATAL).The logging statements are then sent to
Appender
s. The appenders can also be configured to accept only statements of a certain importance level, one above a certain "threshold".A configuration like:
tells the appender to only accept statements of ERROR importance or above (i.e. ERROR and FATAL).
In your example the log level is set to DEBUG. What gets written by the appenders is orthogonal to the issue.
As for your two examples:
1. Logger priority set to DEBUG and appender threshold set to ERROR means that the logger passes along DEBUG, INFO, WARN, ERROR and FATAL but appender only accepts ERROR and FATAL so you get only ERROR and FATAL into your log.
2. Logger priority set to ERROR and appender threshold set to DEBUG means that the logger passes along only ERROR and FATAL while the appender accepts DEBUG, INFO, WARN, ERROR and FATAL. You again get only ERROR and FATAL into your log.
But that's just an unfortunate case. Mixing the priority and the threshold can get you some nice functionality. For example...
... assume you just placed an application in staging and you need to monitor it for a bit until you move it to production. You have a developer and a system administrator doing the monitoring. While the developer want all the logs, the system administrator is busy and only wants to see the errors.
How do you configure that? How about something like this:
If you run code like:
you get this in
sysAdminLogs.log
:and this in
developerLogs.log
:Hope this explanation better describes the concepts.