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

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>

 



Add a Comment




We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.




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




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |