Created
November 3, 2021 07:56
-
-
Save mavek87/c84a573e9c7d42aa62755967eed387e7 to your computer and use it in GitHub Desktop.
Set logging programmatically (Logback and slf4j)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ch.qos.logback.classic.Level; | |
import ch.qos.logback.classic.Logger; | |
import ch.qos.logback.classic.LoggerContext; | |
import org.slf4j.LoggerFactory; | |
import java.util.List; | |
public final class LoggerService { | |
private static final org.slf4j.Logger logger = LoggerFactory.getLogger(LoggerService.class); | |
public static void setLogLevel(final Level level) { | |
LoggerContext loggerContext = ((ch.qos.logback.classic.Logger) logger).getLoggerContext(); | |
List<Logger> loggerList = loggerContext.getLoggerList(); | |
for (ch.qos.logback.classic.Logger logger : loggerList) { | |
logger.setLevel(level); | |
} | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module com.xxx.mymodule { | |
requires org.slf4j; | |
requires logback.core; | |
requires logback.classic; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment