What does the threshold value mean in Log4J?

Hello everyone. I have log4j properties as shown below. Everything registered in TextProcessor.log is above the WARN. I do not understand the threshold that is set here for debugging. Can someone explain what the threshold value is

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 

Thank you in advance

+75
java logging log4j
Feb 25 2018-11-21T00:
source share
4 answers

You have two things: the registrar and the application. Unfortunately, you have chosen the same name for both, which does not make it very clear.

The minimum log level is set for warning, which means that everything that you register with this logger, which does not have at least a warning level, will be ignored.

As soon as the message is received by the registrar, it is sent to one or several applications (to a file, to the console, to the mail server, etc.). Each of these additives can define a threshold. For example, you can limit console messages to errors, but accept warnings in the log file.

+119
Feb 25 '11 at 16:50
source share

Threshold is the second filter for registering messages

eg:

  log4j.logger.TextProcessor=Debug,TextProcessor , InfoLogger . . . log4j.appender.TextProcessor.Threshold=Error 

if Logger is set to DEBUG and appender. The threshold is set to Error, and only with the TextProcessor application only Error and messages with a higher severity will be logged.

Using the threshold - you can define another appender with different threshold levels, for example, in the above example, you can also enable InfoLogger with the Info level message protocol enabled

  log4j.logger.TextProcessor=Debug,TextProcessor , InfoLogger . . . log4j.appender.InfoLogger.Threshold=INFO 

To understand the levels, in log4j below are the logging levels :

 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

+27
Apr 01 '14 at 6:58
source share

Registration Levels: TRACE , DEBUG , INFO , WARN , ERROR and FATAL . You can choose what to register at what level of code, depending on the severity. For example, you will have the opportunity to register the entry and exit of methods, but you can register at the DEBUG level. This will help you debug the code, because by default it will be displayed on the console (the console console is turned on by default). When you switch to production, you can increase the threshold to ERROR and prevent the application from printing out not-so-useful information about console or log files.

+25
Feb 25 2018-11-21T00:
source share

Easily map a property configuration file to a log message stream. (I hid a few configuration lines to minimize)

 log4j.rootLogger=ALL, stdout log4j.logger.com.xyz=INFO, file log4j.appender.stdout=org.apache.log4j.ConsoleAppender log4j.appender.stdout.Threshold=DEBUG ... log4j.appender.file=org.apache.log4j.RollingFileAppender log4j.appender.file.Threshold=WARN ... 

schema of logging from settings above

To understand what it is, you must know that:

  • Registration levels increase when retrieving from the left: TRACE, DEBUG, INFO, WARN, ERROR and FATAL
  • Registration of the minimum level that the registrar accepts from the application.
  • Minimum application login level that decides what will be written

** There is something more complicated about inheritance and additivity, but first you have to start with simple and simple things.

+9
Oct 07 '17 at 8:05
source share



All Articles