Bootstrap FreeKB - Java - LogConfig.xml (log level)
Java - LogConfig.xml (log level)

Updated:   |  Java articles

In your Java apps web.xml file, add the following.

<context-param>
  <description>logbackConfigLocation</description>
  <param-name>logbackConfigLocation</param-name>
  <param-value>file:/path/to/LogConfig.xml</param-value>
</context-param>

 

Here is an example of what LogConfig.xml may contain.

<?xml version="1.0" encoding="UTF-8" ?>
<configuration>
  <property name="LOG_FILE" value="myLog"/>
  <property name="APPENDER" value="STDOUT" />
  <contextName>${LOG_FILE}</contextName>
  <appender name="${LOG_FILE}" class="ch.qos.logback.core.rolling.RollingFileAppender">
    <file>$/path/to/${LOG_FILE}.log</file>

    <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
      <fileNamePattern>/path/to/${LOG_FILE}.log.%i</fileNamePattern>
      <minIndex>1</minIndex>
      <maxIndex>5</maxIndex>
    </rollingPolicy>

    <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
      <maxFileSize>10MB</maxFileSize>
    </triggeringPolicy>

    <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
      <layout class="com.acme.securityutils.log.SecurePatternLayout">
        <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
      </layout>
    </encoder>
  </appender>

  <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
    <encoder class="ch.qos.logback.core.encoder.LayoutWrappingEncoder">
      <layout class="com.acme.securityutils.log.SecurePatternLayout">
        <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%n</pattern>
      </layout>
    </encoder>
  </appender>

  <logger name="com.acme.contract" level="debug"/>
  <logger name="com.acme.myApp" level="debug"/>
  <logger name="org.hibernate" level="error"/>
  <logger name="org.springframework" level="error"/>
  <root level="error">
    <appender-ref ref="${LOG_FILE}"/>
  </root>
</configuration>

 




Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee



Comments


Add a Comment


Please enter e22a13 in the box below so that we can be sure you are a human.