@Plugin(name="LoggerNamePatternSelector",
category="Core",
elementType="patternSelector")
public class LoggerNamePatternSelector
extends java.lang.Object
implements org.apache.logging.log4j.core.layout.PatternSelector
PatternSelector
that selects patterns based on the logger name.
Can be used to log messages from different loggers using different patterns.
Multiple logger names may be separated using comma in the
PatternMatch "key"
. The pattern will be applied
if the logger name matches at least one of them.
Example usage:
<PatternLayout>
<LoggerNamePatternSelector defaultPattern="[%d{HH:mm:ss} %level] [%logger]: %msg%n">
<!-- Log root (empty logger name), "Main", and net.minecrell.* without logger prefix -->
<PatternMatch key=",Main,net.minecrell." pattern="[%d{HH:mm:ss} %level]: %msg%n"/>
<PatternMatch key="com.example.Logger" pattern="EXAMPLE: %msg%n"/>
</LoggerNamePatternSelector>
</PatternLayout>
Modifier and Type | Class and Description |
---|---|
private static class |
LoggerNamePatternSelector.LoggerNameSelector |
Modifier and Type | Field and Description |
---|---|
private org.apache.logging.log4j.core.pattern.PatternFormatter[] |
defaultFormatters |
private java.util.List<LoggerNamePatternSelector.LoggerNameSelector> |
formatters |
Modifier | Constructor and Description |
---|---|
protected |
LoggerNamePatternSelector(java.lang.String defaultPattern,
org.apache.logging.log4j.core.layout.PatternMatch[] properties,
boolean alwaysWriteExceptions,
boolean disableAnsi,
boolean noConsoleNoAnsi,
org.apache.logging.log4j.core.config.Configuration config)
Constructs a new
LoggerNamePatternSelector . |
Modifier and Type | Method and Description |
---|---|
static LoggerNamePatternSelector |
createSelector(java.lang.String defaultPattern,
org.apache.logging.log4j.core.layout.PatternMatch[] properties,
boolean alwaysWriteExceptions,
boolean disableAnsi,
boolean noConsoleNoAnsi,
org.apache.logging.log4j.core.config.Configuration config)
Creates a new
LoggerNamePatternSelector . |
org.apache.logging.log4j.core.pattern.PatternFormatter[] |
getFormatters(org.apache.logging.log4j.core.LogEvent event) |
private static org.apache.logging.log4j.core.pattern.PatternFormatter[] |
toArray(java.util.List<org.apache.logging.log4j.core.pattern.PatternFormatter> formatters) |
private final org.apache.logging.log4j.core.pattern.PatternFormatter[] defaultFormatters
private final java.util.List<LoggerNamePatternSelector.LoggerNameSelector> formatters
protected LoggerNamePatternSelector(java.lang.String defaultPattern, org.apache.logging.log4j.core.layout.PatternMatch[] properties, boolean alwaysWriteExceptions, boolean disableAnsi, boolean noConsoleNoAnsi, org.apache.logging.log4j.core.config.Configuration config)
LoggerNamePatternSelector
.defaultPattern
- The default pattern to use if no logger name matchesproperties
- The pattern match rules to usealwaysWriteExceptions
- Write exceptions even if pattern does not
include exception conversiondisableAnsi
- If true, disable all ANSI escape codesnoConsoleNoAnsi
- If true and System.console()
is null,
disable ANSI escape codesconfig
- The configurationprivate static org.apache.logging.log4j.core.pattern.PatternFormatter[] toArray(java.util.List<org.apache.logging.log4j.core.pattern.PatternFormatter> formatters)
public org.apache.logging.log4j.core.pattern.PatternFormatter[] getFormatters(org.apache.logging.log4j.core.LogEvent event)
getFormatters
in interface org.apache.logging.log4j.core.layout.PatternSelector
@PluginFactory public static LoggerNamePatternSelector createSelector(@Required(message="Default pattern is required") @PluginAttribute(value="defaultPattern") java.lang.String defaultPattern, @PluginElement(value="PatternMatch") org.apache.logging.log4j.core.layout.PatternMatch[] properties, @PluginAttribute(value="alwaysWriteExceptions",defaultBoolean=true) boolean alwaysWriteExceptions, @PluginAttribute(value="disableAnsi") boolean disableAnsi, @PluginAttribute(value="noConsoleNoAnsi") boolean noConsoleNoAnsi, @PluginConfiguration org.apache.logging.log4j.core.config.Configuration config)
LoggerNamePatternSelector
.defaultPattern
- The default pattern to use if no logger name matchesproperties
- The pattern match rules to usealwaysWriteExceptions
- Write exceptions even if pattern does not
include exception conversiondisableAnsi
- If true, disable all ANSI escape codesnoConsoleNoAnsi
- If true and System.console()
is null,
disable ANSI escape codesconfig
- The configuration