Log4j2 config

An example Log4j2 configuration file, with custom colorization console output.

<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="error" packages="com.thomaswilde.fact.application">

  <Appenders>
    <Console name="Console" target="SYSTEM_OUT">
      <PatternLayout disableAnsi="false" pattern="%d %highlight{%-7level}{FATAL=red, ERROR=red, WARN=yellow, INFO=green, DEBUG=blue, TRACE=grey} %-60logger{36} Line %-5L %-20M - %highlight{%msg}{FATAL=red, ERROR=red, WARN=yellow, INFO=green, DEBUG=blue, TRACE=grey}%n"/>
    </Console>
    <File name="MyFile" fileName="logs/app.log" append="false">
<!--      <PatternLayout pattern="%d %-7level %logger{36} - %msg%n"/>-->
      <PatternLayout pattern="%d %-7level %-60logger{36} Line %-5L %-20M - %msg%n"/>
    </File>
    <LogInterceptor name="CustomAppender">
      <PatternLayout pattern="%d %-7level %-60logger{36} Line %-5L %-20M - %msg%n"/>
    </LogInterceptor>
  </Appenders>
  <Loggers>
    <Logger name="com.thomaswilde.wildebeans.database.DbUtil2" level="DEBUG" />
    <Logger name="com.thomaswilde.fxcore.FXPropertyUtils" level="DEBUG" />
    <Logger name="com.thomaswilde.wildebeans.WildeBeanTable" level="DEBUG" />
    <Logger name="com.thomaswilde.wildebeans.WildePropertySheet3" level="DEBUG" />
    <Logger name="com.thomaswilde.fact.application.AppPreferences" level="INFO" />
    <Logger name="com.thomaswilde.fact.entities.data.Job" level="DEBUG" />
    <Logger name="com.thomaswilde.wildebeans.WildeBean" level="DEBUG" />
    <Logger name="org.apache.hc.client5.http" level="INFO" />
    <Root level="INFO">
      <!-- Only events at DIAG level or more specific are sent to the console. -->
      <AppenderRef ref="Console" level="verbose" />
      <AppenderRef ref="MyFile" level="trace" />
      <AppenderRef ref="CustomAppender" level="trace" />
    </Root>
  </Loggers>
</Configuration>

Comments