概述
logback.xml:
<configuration>
<Properties>
<Property name="logdir">/opt/apache-tomcat-8.5.4/logs/OnePNSApiServer</Property>
</Properties>
<appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread] %logger - %msg%n
</pattern>
</encoder>
</appender>
<appender name="INFOOUT"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<filter class="ch.qos.logback.classic.filter.ThresholdFilter" >
<level>INFO</level>
</filter>
<file>/opt/apache-tomcat-8.5.4/logs/OnePNSApiServer/OnePNSApiServer_info.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- Daily rollover -->
<fileNamePattern>/opt/apache-tomcat-8.5.4/logs/OnePNSApiServer/OnePNSApiServer_info.%d{yyyy-MM-dd}.log
</fileNamePattern>
<!-- Keep 180 days' worth of history -->
<maxHistory>180</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread] %logger - %msg%n
</pattern>
</encoder>
</appender>
<appender name="DEBUGOUT"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>DEBUG</level>
</filter>
<file>/opt/apache-tomcat-8.5.4/logs/OnePNSApiServer/OnePNSApiServer_debug.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- Daily rollover -->
<fileNamePattern>/opt/apache-tomcat-8.5.4/logs/OnePNSApiServer/OnePNSApiServer_debug.%d{yyyy-MM-dd}.log
</fileNamePattern>
<!-- Keep 180 days' worth of history -->
<maxHistory>180</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread] %logger - %msg%n
</pattern>
</encoder>
</appender>
<appender name="ERROROUT"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<filter class="ch.qos.logback.classic.filter.ThresholdFilter">
<level>ERROR</level>
</filter>
<file>/opt/apache-tomcat-8.5.4/logs/OnePNSApiServer/OnePNSApiServer_error.log</file>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- Daily rollover -->
<fileNamePattern>/opt/apache-tomcat-8.5.4/logs/OnePNSApiServer/OnePNSApiServer_error.%d{yyyy-MM-dd}.log
</fileNamePattern>
<!-- Keep 180 days' worth of history -->
<maxHistory>180</maxHistory>
</rollingPolicy>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level [%thread] %logger - %msg%n
</pattern>
</encoder>
</appender>
<!-- DB error log -->
<appender name="DBDOWNAppen"
class="ch.qos.logback.core.rolling.RollingFileAppender">
<file>/opt/apache-tomcat-8.5.4/logs/OnePNSApiServer/onepns_db_error.log</file>
<encoder>
<pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} %-5level-%msg%n</pattern>
</encoder>
<filter class="ch.qos.logback.classic.filter.LevelFilter">
<level>ERROR</level>
</filter>
<rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
<!-- Daily rollover -->
<fileNamePattern>/opt/apache-tomcat-8.5.4/logs/OnePNSApiServer/onepns_db_error.%d{yyyy-MM-dd}.log
</fileNamePattern>
<!-- Keep 180 days' worth of history -->
<maxHistory>180</maxHistory>
</rollingPolicy>
<triggeringPolicy
class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
<maxFileSize>50KB</maxFileSize>
</triggeringPolicy>
</appender>
<!-- Configure so that it outputs to both console and log file --> 设置输出哪些log
<root level="DEBUG">
<appender-ref ref="STDOUT" />
<appender-ref ref="INFOOUT" />
<appender-ref ref="DEBUGOUT" />
<appender-ref ref="ERROROUT" />
</root>
<logger name="DBDOWN_ALERTLOG" level="ERROR">
<appender-ref ref="DBDOWNAppen" />
</logger>
<logger name="org.springframework" level="warn" />
<logger name="net.sf.ehcache" level="warn" />
</configuration>
log4j.xml:
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE log4j:configuration PUBLIC "-//LOGGER" "log4j.dtd"> <log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/"> <!-- Appenders --> <appender name="console" class="org.apache.log4j.ConsoleAppender"> <param name="Target" value="System.out" /> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d %t %-5p: %c - %m%n" /> </layout> </appender> <!-- Appenders --> <appender name="file" class="org.apache.log4j.DailyRollingFileAppender"> <param name="File" value="/opt/ibwifi/logs/ibwifi.log"/> <param name="Append" value="true"/> <param name="DatePattern" value="'.'yyyyMMdd"/> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="%d %t %-5p: %c - %m%n" /> </layout> </appender> <!-- 3rdparty Loggers --> <logger name="org.springframework.core"> <level value="info" /> </logger> <logger name="org.springframework.beans"> <level value="info" /> </logger> <logger name="org.springframework.context"> <level value="info" /> </logger> <logger name="org.springframework.web"> <level value="info" /> </logger> <logger name="org.eclipse.jetty.util.log"> <level value="warn" /> </logger> <!-- Root Logger --> 这里设置显示级别,屏蔽不需要的级别 <root> <priority value="debug" /> <appender-ref ref="console" /> <appender-ref ref="file" /> </root> </log4j:configuration>
最后
以上就是谦让铅笔为你收集整理的log4j.xml & logback.xml实例的全部内容,希望文章能够帮你解决log4j.xml & logback.xml实例所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复