-
Notifications
You must be signed in to change notification settings - Fork 1
io microsphere logging log4j2 util Log4j2Utils
Type: Class | Module: microsphere-log4j2 | Package: io.microsphere.logging.log4j2.util | Since: 1.0.0
Source:
microsphere-log4j2/src/main/java/io/microsphere/logging/log4j2/util/Log4j2Utils.java
The utilities class for Log4j2
public abstract class Log4j2Utils implements UtilsAuthor: Mercy
-
Introduced in:
1.0.0 -
Current Project Version:
0.1.14-SNAPSHOT
This component is tested and compatible with the following Java versions:
| Java Version | Status |
|---|---|
| Java 8 | ✅ Compatible |
| Java 11 | ✅ Compatible |
| Java 17 | ✅ Compatible |
| Java 21 | ✅ Compatible |
| Java 25 | ✅ Compatible |
Log4j2Utils.doInLogger(logger -> logger.setLevel(Level.DEBUG));InMemoryAppender appender = new InMemoryAppender();
Collection<Logger> loggers = Log4j2Utils.getLoggers();
Log4j2Utils.addAppender(appender, loggers);InMemoryAppender appender = new InMemoryAppender();
Log4j2Utils.addAppenderForAllLoggers(appender);InMemoryAppender appender = new InMemoryAppender();
Collection<Logger> loggers = Log4j2Utils.getLoggers();
Log4j2Utils.removeAppender(appender, loggers);InMemoryAppender appender = Log4j2Utils.findAppender(InMemoryAppender.NAME);
Log4j2Utils.removeAppenderForAllLoggers(appender);Add the following dependency to your pom.xml:
<dependency>
<groupId>io.github.microsphere-projects</groupId>
<artifactId>microsphere-log4j2</artifactId>
<version>${microsphere-logging.version}</version>
</dependency>Tip: Use the BOM (
microsphere-logging-dependencies) for consistent version management. See the Getting Started guide.
import io.microsphere.logging.log4j2.util.Log4j2Utils;| Method | Description |
|---|---|
getConfiguration |
Get the Configuration
|
getLogger |
Get the Logger by specified name |
getLogger |
Get the Logger by the request class |
getLevel |
Get the Level of Logger by the specified logger name |
getLevel |
Get the Level of Logger |
setLoggerLevel |
Set the Level of Logger by the specified logger name |
setLoggerLevel |
Set the Level of Logger |
setLoggerLevel |
Set the Level of Logger |
getLevelString |
Get the Level String of Logger by the specified logger name |
getLevelString |
Get the Level String of Logger |
findAppender |
Find the Appender by its name |
getLoggerContext |
Get the LoggerContext
|
getLoggers |
Get all Logger loggers
|
doInLogger |
Apply the given Consumer to each Logger in the current LoggerContext. |
addAppender |
Add the given Appender to the specified Logger instances. |
addAppenderForAllLoggers |
Add the given Appender to all Logger instances in the current LoggerContext. |
removeAppender |
Remove the given Appender from the specified Logger instances. |
removeAppenderForAllLoggers |
Remove the given Appender from all Logger instances in the current LoggerContext. |
public static Level getLevel(@Nonnull String loggerName)Get the Level of Logger by the specified logger name
public static void setLoggerLevel(String loggerName, String levelName)Set the Level of Logger by the specified logger name
public static String getLevelString(@Nonnull String loggerName)Get the Level String of Logger by the specified logger name
public static void doInLogger(Consumer<Logger> loggerConsumer)Apply the given Consumer to each Logger in the current LoggerContext.
`Log4j2Utils.doInLogger(logger -> logger.setLevel(Level.DEBUG)); `
public static void addAppender(Appender appender, Iterable<Logger> loggers)Add the given Appender to the specified Logger instances.
`InMemoryAppender appender = new InMemoryAppender(); Collection loggers = Log4j2Utils.getLoggers(); Log4j2Utils.addAppender(appender, loggers); `
public static void addAppenderForAllLoggers(Appender appender)Add the given Appender to all Logger instances in the current LoggerContext.
`InMemoryAppender appender = new InMemoryAppender(); Log4j2Utils.addAppenderForAllLoggers(appender); `
public static void removeAppender(Appender appender, Iterable<Logger> loggers)Remove the given Appender from the specified Logger instances.
`InMemoryAppender appender = new InMemoryAppender(); Collection loggers = Log4j2Utils.getLoggers(); Log4j2Utils.removeAppender(appender, loggers); `
public static void removeAppenderForAllLoggers(Appender appender)Remove the given Appender from all Logger instances in the current LoggerContext.
`InMemoryAppender appender = Log4j2Utils.findAppender(InMemoryAppender.NAME); Log4j2Utils.removeAppenderForAllLoggers(appender); `
LoggerContextConfigurationLogger
This documentation was auto-generated from the source code of microsphere-logging.
java-logging
log4j
log4j2
- DelegatingLayout
- InMemoryAppender
- Log4j2Logger
- Log4j2LoggerFactory
- Log4j2Logging
- Log4j2Utils
- LogEventComparator
- SmartFileAppenderLayout
logback
logging-commons
- DefaultLoggingLevelsResolver
- Logging
- LoggingLevelsResolver
- LoggingMXBeanAdapter
- LoggingMXBeanRegistrar
- LoggingUtils
logging-examples
logging-test