I am attempting to set logging levels separately for 2 nested class loggers, an example of this being loggers that are named:
com.package.ParentClass$LoggerOne and com.package.ParentClass$LoggerTwo. Adding loggers in the logback.xml file for those exact loggers works fine, but it doesn't seem to have any effect when trying to set the loggers for spring boot's logging.level properties group.
A class with these loggers would look something like this:
class ParentClass {
private static Logger logger = LoggerFactory.getLogger(ParentClass.class);
// code that uses ParentClass logger
class LoggerOne {
private static Logger logger = LoggerFactory.getLogger(LoggerOne.class);
// code that uses LoggerOne logger
}
class LoggerTwo {
private static Logger logger = LoggerFactory.getLogger(LoggerTwo.class);
// code that uses LoggerTwo logger
}
}
The solution, as found on this GitHub issues comment, is to surround the logger class / sub-class in [].
Example:
logging:
level:
com.package.[ParentClass$LoggerOne]: INFO
com.package.[ParentClass$LoggerTwo]: ERROR
com.package.ParentClass: DEBUG
This allows fine-grained control of logging levels for the parent class and any nested class contained within the parent.
I tried to use brackets, and it works for me:
logging.level.com.package[ParentClass$LoggerOne]=INFO
logging.level.com.package[ParentClass$LoggerTwo]=DEBUG
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