Hi All I have a log4j properties something like the below. Everything that is logged in TextProcessor.log is something is above above WARN level. I don't understand the threshold that is set here to debug. Can someone explain what the threshold does
log4j.logger.TextProcessor=warn,TextProcessor
log4j.appender.TextProcessor=org.apache.log4j.RollingFileAppender
log4j.appender.TextProcessor.File=C:/project/logs/TextProcessor.log
log4j.appender.TextProcessor.MaxFileSize=10MB
log4j.appender.TextProcessor.MaxBackupIndex=10
log4j.appender.TextProcessor.Threshold=debug
log4j.appender.TextProcessor.layout=org.apache.log4j.PatternLayout
log4j.appender.TextProcessor.layout.ConversionPattern=[%d] [%5p] (%F:%L) - %m%n
Thanks in advance
You have two things here : a logger, and an appender. Unfortunately, you chose the same name for both, which doesn't make it very clear.
The logger's minimum level is set to warn, which means everything you log with this logger which doesn't have at least the warn level will be ignored.
Once a message is accepted by the logger, it's sent to one or several appenders (to a file, to the console, to a mail server, etc.). Each of these appenders may define a threshold. You could for example limit the messages in the console to errors, but accept warn messages in the log file.
Give you simple mapping from properties config file to flow of log messages. (I hid some lines of config to minimize)
To understand what it is, you should know that:
** There are some thing more complex about inheritance and additivity, but you should start at basic and simple things first.
Threshold is second filter for messages to be logged
e.g.:
if Logger is set at level DEBUG and appender Threshold is set at Error then with the appender TextProcessor only Error and higher severity messages would be logged.
Use of Threshold is ,you can define different appender with different threshold levels ,for e.g in above mentioned example you can also have InfoLogger with Info level messages logging enabled
To understand levels , There are below levels of logging in log4j:
go to URL for more details
The levels of logging are
TRACE
,DEBUG
,INFO
,WARN
,ERROR
andFATAL
. You will be able to choose what to log at what level in the code depending on the severity. For example you will have the ability to log entry and exit of methods but can choose to log at theDEBUG
level. This will help you to debug the code as by default it will print out on the console (default console appender is on). While going to production you can increase the threshold toERROR
and prevent the application from printing out not so useful details on the console or log files.