I have a log4j
properties something like below. Everything that is logged in TextProcessor.log
is something 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
If we set the log level to ' X ' then any log request with ' level <= X ' (lesser scopes) will be logged in log files. All requests with higher-order will not be logged. For example, If we set the logging level to INFO , then the application will log messages with scopes – INFO , WARN , ERROR and FATAL .
log4j has three main components: loggers: Responsible for capturing logging information. appenders: Responsible for publishing logging information to various preferred destinations. layouts: Responsible for formatting logging information in different styles.
The rootlogger is always the logger configured in the log4j. properties file, so every child logger used in the application inherits the configuration of the rootlogger . The logging levels are (from smaller to greater) : ALL, DEBUG, INFO, WARN, ERROR, FATAL, OFF .
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.
Threshold is second filter for messages to be logged
e.g.:
log4j.logger.TextProcessor=Debug,TextProcessor , InfoLogger . . . log4j.appender.TextProcessor.Threshold=Error
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
log4j.logger.TextProcessor=Debug,TextProcessor , InfoLogger . . . log4j.appender.InfoLogger.Threshold=INFO
To understand levels , There are below levels of logging in log4j:
FATAL: shows messages at a FATAL level only ERROR: Shows messages classified as ERROR and FATAL WARNING: Shows messages classified as WARNING, ERROR, and FATAL INFO: Shows messages classified as INFO, WARNING, ERROR, and FATAL DEBUG: Shows messages classified as DEBUG, INFO, WARNING, ERROR, and FATAL TRACE : Shows messages classified as TRACE,DEBUG, INFO, WARNING, ERROR, and FATAL ALL : Shows messages classified as TRACE,DEBUG, INFO, WARNING, ERROR, and FATAL OFF : No log messages display
go to URL for more details
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With