Class LoggerNamePatternSelector

java.lang.Object
net.fabricmc.log4j.LoggerNamePatternSelector
All Implemented Interfaces:
org.apache.logging.log4j.core.layout.PatternSelector

@Plugin(name="LoggerNamePatternSelector", category="Core", elementType="patternSelector") public final class LoggerNamePatternSelector extends Object implements org.apache.logging.log4j.core.layout.PatternSelector
A 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>
  • Field Summary

    Fields inherited from interface org.apache.logging.log4j.core.layout.PatternSelector

    ELEMENT_TYPE
  • Method Summary

    Modifier and Type
    Method
    Description
    createSelector(String defaultPattern, org.apache.logging.log4j.core.layout.PatternMatch[] properties, boolean alwaysWriteExceptions, boolean disableAnsi, boolean noConsoleNoAnsi, org.apache.logging.log4j.core.config.Configuration config)
    org.apache.logging.log4j.core.pattern.PatternFormatter[]
    getFormatters(org.apache.logging.log4j.core.LogEvent event)
     

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • getFormatters

      public org.apache.logging.log4j.core.pattern.PatternFormatter[] getFormatters(org.apache.logging.log4j.core.LogEvent event)
      Specified by:
      getFormatters in interface org.apache.logging.log4j.core.layout.PatternSelector
    • createSelector

      @PluginFactory public static LoggerNamePatternSelector createSelector(@Required(message="Default pattern is required") @PluginAttribute("defaultPattern") String defaultPattern, @PluginElement("PatternMatch") org.apache.logging.log4j.core.layout.PatternMatch[] properties, @PluginAttribute(value="alwaysWriteExceptions",defaultBoolean=true) boolean alwaysWriteExceptions, @PluginAttribute("disableAnsi") boolean disableAnsi, @PluginAttribute("noConsoleNoAnsi") boolean noConsoleNoAnsi, @PluginConfiguration org.apache.logging.log4j.core.config.Configuration config)
      Parameters:
      defaultPattern - The default pattern to use if no logger name matches
      properties - The pattern match rules to use
      alwaysWriteExceptions - Write exceptions even if pattern does not include exception conversion
      disableAnsi - If true, disable all ANSI escape codes
      noConsoleNoAnsi - If true and System.console() is null, disable ANSI escape codes
      config - The configuration
      Returns:
      The new pattern selector