There are lines in the configuration file: <Logger name = "Ru.we.RR" level="debug"/> and also <root level = "info"> . What do these lines mean?
- If you are given an exhaustive answer, mark it as correct (tick the selected answer). - Mikhail Vaysman
1 answer
Logback has a Logger concept. Logger is an object with which logging is performed. It has several methods by which you can create records with different levels. Level is a parameter allowing to describe the importance of a message. The logback has the following level:
- TRACE (highest)
- DEBUG
- INFO
- WARN
- ERROR
- FATAL (lowest)
Each Logger can be configured to filter records of a specific level. If the recording level is higher than the Logger level, then this record will be ignored.
All Loggers are organized in a tree hierarchy. The root logger is called root . A developer can add his Logger to the hierarchy. The place of the logger in the hierarchy depends on its name. For example, a Logger with the name Ru.we.RR is located in the subtree of Ru.we , which, in turn, is located in the Ru subtree and terminates everything root . If the Logger does not have a level, then it takes the level of its ancestor.
<root level = "info"> - means that root (root of the tree) will have the INFO level set and this level will be descendants if it is not explicitly set in the configuration file. <Logger name = "Ru.we.RR" level="debug"/> - means that Ru.we.RR and its descendants will have a DEBUG level.
Which levels to choose when using the Logger in code depends on the rules that are adopted in the development team. But I usually use the following option:
- FATAL is the "deathbed" message, after which the system shuts down
- ERROR - errors in the input data that can not be corrected. The message must have this input.
- WARN - errors in the input data that can be corrected, for example, the outdated (deprecated) type of the input parameter is used.
- INFO - almost not using
- DEBUG - information about each "sneeze" inside the system, received something at the entrance - recorded in the log, counted something - recorded in the log
- TRACE - almost never use
- Another word about the meaning of levels is a couple of words or a link, otherwise they are always used haphazardly (at least in my experience). :) - Nick Volynkin ♦
- Do you mean what is the difference between, for example, WARN and ERROR? - Mikhail Vaysman
- yes, like so. - Nick Volynkin ♦
- Very cool explanation) thank you for the super detailed answer)))! There is another point <contextListener class = "ch.qos.logback.classic.jul.LevelChangePropagator"> <resetJUL> true </ resetJUL> </ contextListener> <! - To enable JMX Management -> <jmxConfigurator /> - alex safsafsd
- What are contextlistener and resetjul for? It is written on the docks about java utill logging, but I’m not catching up on what exactly is, English is still a bit weak ( - alex safsafsd