In response of @MiguelMunoz, here is a working implementation using LoggerContext.
Tested on JDK 17 with :
org.slf4j:slf4j-api:2.0.10
ch.qos.logback:logback-classic:1.5.12
package logger;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.LoggerContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class LoggerTest {
static final Logger LOGGER = LoggerFactory.getLogger(LoggerTest.class);
public static void main(String[] args) {
LOGGER.info("Should appear");
LOGGER.debug("Should appear");
LoggerContext ctx = (LoggerContext) LoggerFactory.getILoggerFactory();
// Use the package name whose level you want to change
ch.qos.logback.classic.Logger logger = ctx.getLogger("logger.LoggerTest");
logger.setLevel(Level.INFO);
LOGGER.debug("Should not appear");
logger.setLevel(Level.DEBUG);
LOGGER.debug("Should reappear");
}
}