快捷搜索:  as  test  1111  test aNd 8=8  test++aNd+8=8  as++aNd+8=8  as aNd 8=8

bet356亚洲版在线体育投注_酒文化网进入



一. Log4j+commons-logging

 JAR包

commons-logging-1.1.jar

log4j-1.2.15.jar

 设置设置设备摆设摆设文件

commons-logging.properties

log4j.xml

 commons-logging.jar包读取commons-logging.properties中指定的log,自动加载日志设置设置设备摆设摆设

在commons-logging+bet356亚洲版在线体育投注log4j组合中commons-logging.properties指定的日志为:

org.apache.commbet356亚洲版在线体育投注ons.logging.Log=org.apache.commons.logging.impl.Log4JLogger

 log4j指定详细日志输出设置设置设备摆设摆设

 假如未选用commons-logging,可以在启动项目中,主动加载log4j的设置设置设备摆设摆设文件

二. Logback+slf4j

 JAR包

slf4j-api-1.5.2.jar

logback-classic-0.9.9.jar

logback-core-0.9.9.jar

 设置设置设备摆设摆设文件

Logback.xml

 logback的加载采纳编码加载

String logbackCfg = "/config/logback.xml";

URL logURL = new ClassPathResource(logbackCfg).getURL();ILoggerFactory loggerFactory = LoggerFactory.getILoggerFactory();

LoggerContext loggerContext = (LoggerContext) loggerFactory;loggerContext.shutdownAndReset();

JoranConfigurator configurator = new JoranConfigurator();configurator.setContext(loggerContext);

configurator.doConfigure(logURL);

三. Slf4j+log4j

 JAR包

slf4j-api-1.5.2.jar

slf4j-log4j12-1.5.2.jar

log4j-1.2.15.jar

 设置设置设备摆设摆设文件

Logback.xml

四. Slf4j+logback+logback

注:这种环境下是项目中有log4j输出的日志以及logback数据的日志.老项目改造,log4j和logback共存的环境下.(被选用spring+slf4j+logback的时刻,spring的日志输出是log4j的,这个时刻采纳这种设置设置设备摆设摆设.)

 JARbao

log4j-over-slf4j-1.5.2.jar

logback-classic-0.9.9.jar

logback-core-0.9.9.jar

slf4j-api-1.5.2.jar

 设置设置设备摆设摆设文件

Logback.xml

 设置设置设备摆设摆设加载

String logbackCfg = "/config/logback.xml";

URL logURL = new ClassPathResource(logbackCfg).getURL();ILoggerFactory loggerFactory = LoggerFactory.getILoggerFactory();

LoggerContext loggerContext = (LoggerContext) loggerFactory;loggerContext.shutdownAndReset();

JoranConfigurator configurator = new JoranConfigurator();configurator.setContext(loggerContext);

configurator.doConfigure(logURL);

五. Log4j设置设置设备摆设摆设文件示例

xml version="1.0" encoding="UTF-8"?>

> log4j:configuration xbet356亚洲版在线体育投注mlns:log4j="http://jakarta.apache.org/log4j/">

appender name="CONSOLE" class="org.apache.log4j.ConsoleAppender">param name="Target" value="System.out" />

param name="Threshold" value="INFO" />layout class="org.apache.log4j.PatternLayout">

param name="ConversionPattern"value="%d{yyyy-MM-dd HH:mm:ss sss}[%-p][%-c][line:%-L] \r\n%m%n" />

layout>

>filter class="org.apache.log4j.varia.StringMatchFilter">

param name="StringToMatch" value="new a seq no spend" />param name="AcceptOnMatch" value="false" />

filter>filter class="org.apache.log4j.varia.StringMatchFilter">

param name="StringToMatch" value="new hi[type=" />param name="AcceptOnMatch" value="false" />

filter>filter class="org.apache.log4j.varia.StringMatchFilter">

param name="StringToMatch" value="FileTransfer.execCommand()" />param name="AcceptOnMatch" value="false" />

filter>appender>

appender name="xxxx_file" class="org.apache.log4j.RollingFileAppender">param name="Append" value="true" />

param name="Threshold" value="INFO" />param name="File" value="xxxx.log" />

param name="MaxFileSize" value="100MB" />param name="MaxBackupIndex" value="15" />

layout class="org.apache.log4j.PatternLayout">param name="ConversionPattern"

value="%d{yyyy-MM-dd HH:mm:ss sss}[%-p][%-c][line:%-L] \r\n%m%n" />layout>

filter class="org.apache.log4j.varia.StringMatchFilter">param name="StringToMatch" value="new a seq no spend" />

param name="AcceptOnMatch" value="false" />filter>

filter class="org.apache.log4j.varia.StringMatchFilter">param name="StringToMatch" value="new hi[type=" />

param name="AcceptOnMatch" value="false" />filter>

filter class="org.apache.log4j.varia.StringMatchFilter">param name="StringToMatch" value="FileTransfer.execCommand()" />

param name="AcceptOnMatch" value="false" />filter>

appender>

appender name="xxxx_error" class="org.apache.log4j.RollingFileAppender">

param name="Append" value="true" />param name="Threshold" value="ERROR" />

param name="File" value="xxxx-error.log" />param name="MaxFileSize" value="100MB" />

param name="MaxBackupIndex" value="4" />layout class="org.apache.log4j.PatternLayout">

param name="ConversionPattern"value="%d{yyyy-MM-dd HH:mm:ss sss}[%-p][%-c][line:%-L] \r\n%m%n" />

layout>appender>

root>appender-ref ref="CONSOLE" />

appender-ref ref="xxxx_file" />bet356亚洲版在线体育投注appender-ref ref="xxxx_file_error" />

root> log4j:configuration>

六. Logback设置设置设备摆设摆设文件示例

xml version="1.0" encoding="UTF-8" ?>

>

configuration>jmxConfigurator />

appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">layout class="ch.qos.logback.classic.PatternLayout">

pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%npattern>layout>

appender>

appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender">

File>xxxx.logFile>rolbet356亚洲版在线体育投注lingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">

FileNamePattern>xxxx.log.%i.bakFileNamePattern>MinIndex>1MinIndex>

MaxIndex>12MaxIndex>rollingPolicy>

triggeringPolicy

class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">MaxFileSize>100MBMaxFileSize>

triggeringPolicy>layout class="ch.qos.logback.classic.PatternLayout">

Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%nPattern>layout>

appender>

appender name="FILE-ERROR" class="ch.qos.logback.core.rolling.RollingFileAppender">filter class="ch.qos.logback.classic.filter.LevelFilter">

level>ERRORlevel>OnMismatch>DENYOnMismatch>

OnMatch>ACCEPTOnMatch>filter>

File>xxxx-err.logFile>

rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">FileNamePattern>xxxx-err.log.%i.bakFileNamePattern>

MinIndex>1MinIndex>MaxIndex>3MaxIndex>

rollingPolicy>triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">

MaxFileSize>100MBMaxFileSize>triggeringPolicy>

layout class="ch.qos.logback.classic.PatternLayout">Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg%nPattern>

layout>appender>

logger name="com.xxx.xxx">level value="INFO" />

appender-ref ref="STDOUT" />appender-ref ref="FILE" />

appender-ref ref="FILE-ERROR" />logger>

configuration>

七. 相关简单阐明

 Log4j

Log4j是Apache的一个开放源代码项目,经由过程应用Log4j,我们可以节制日志信息运送的目的地是节制台、文件、GUI组件、以致是套接口办事 器、NT的事故记录器、UNIX Syslog守护进程等;用户也可以节制每一条日志的输出款式;经由过程定义每一条日志信息的级别,用户能够加倍细致地节制日志的天生历程。这些可以经由过程一个 设置设置设备摆设摆设文件来机动地进行设置设置设备摆设摆设,而不必要改动法度榜样代码

 Slf4j

简单日记门面(Facade)SLF4J是为各类loging APIs供给一个简单统一的接口,从而使得终极用户能够在支配的时刻设置设置设备摆设摆设自己盼望的loging APIs实现。 Logging API实现既可以选择直接实现SLF4J接的loging APIs如: NLOG4J、SimpleLogger。也可以经由过程SLF4J供给的API实现来开拓响应的适配器如Log4jLoggerAdapter、JDK14LoggerAdapter。

 Logback

Logback是由log4j开创人设计的又一个开源日记组件。logback当前分成三个模块:logback-core,logback- classic和logback-access。logback-core是其它两个模块的根基模块。logback-classic是log4j的一个 改善版本。此外logback-classic完备实现SLF4J API使你可以很方便地替换成其它日记系统如log4j或JDK14 Logging。logback-access造访模块与Servlet容器集成供给经由过程Http来造访日记的功能。

免责声明:以上内容源自网络,版权归原作者所有,如有侵犯您的原创版权请告知,我们将尽快删除相关内容。

您可能还会对下面的文章感兴趣: