In log4j
it's possible to define log levels by package
as follows:
<logger name="org.springframework.web.servlet.mvc.method.annotation" level="info">
<AppenderRef ref="CONSOLE" />
</logger>
Questin: how can I define the logging for a specific class only? (eg org.springframework.web.servlet.mvc.method.annotation.EndpointHandlerMapping
)? If I just put this into the <logger name
property, nothing is logged anymore.
To define a custom log level in code, use the Level. forName() method. This method creates a new level for the specified name. After a log level is defined you can log messages at this level by calling the Logger.
Configuration: the root element of a log4j2 configuration file; the status attribute represents the level at which internal log4j events should be logged. Appenders: this element contains a list of appenders; in our example, an appender corresponding to the System console is defined.
It should work with fully qualified name as well. Logger.name doesnt have to be package/class only but it could be any name which you want to. When you call LoggerFactory.getLogger("MyLogger"), then you have to use
<Logger name="MyLogger" level="info">
<AppenderRef ref="CONSOLE"/>
</Logger>
Check what is logged when you use logger for package and use logger name from log. What logger name is logged for this class?
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