- 浏览: 984727 次
文章分类
- 全部博客 (428)
- Hadoop (2)
- HBase (1)
- ELK (1)
- ActiveMQ (13)
- Kafka (5)
- Redis (14)
- Dubbo (1)
- Memcached (5)
- Netty (56)
- Mina (34)
- NIO (51)
- JUC (53)
- Spring (13)
- Mybatis (17)
- MySQL (21)
- JDBC (12)
- C3P0 (5)
- Tomcat (13)
- SLF4J-log4j (9)
- P6Spy (4)
- Quartz (12)
- Zabbix (7)
- JAVA (9)
- Linux (15)
- HTML (9)
- Lucene (0)
- JS (2)
- WebService (1)
- Maven (4)
- Oracle&MSSQL (14)
- iText (11)
- Development Tools (8)
- UTILS (4)
- LIFE (8)
最新评论
-
Donald_Draper:
Donald_Draper 写道刘落落cici 写道能给我发一 ...
DatagramChannelImpl 解析三(多播) -
Donald_Draper:
刘落落cici 写道能给我发一份这个类的源码吗Datagram ...
DatagramChannelImpl 解析三(多播) -
lyfyouyun:
请问楼主,执行消息发送的时候,报错:Transport sch ...
ActiveMQ连接工厂、连接详解 -
ezlhq:
关于 PollArrayWrapper 状态含义猜测:参考 S ...
WindowsSelectorImpl解析一(FdMap,PollArrayWrapper) -
flyfeifei66:
打算使用xmemcache作为memcache的客户端,由于x ...
Memcached分布式客户端(Xmemcached)
使用logback轻松管理日志: http://blog.csdn.net/mydeman/article/details/6716925
Logback日志使用详解:http://www.cnblogs.com/davidwang456/p/4448011.html
logback的介绍-配置:http://sunney2010.iteye.com/blog/1404723
slf4j + Logback详解:http://donald-draper.iteye.com/admin/blogs/2332433
需要的jar
slf4j-api.jar
logback-core.jar
logback-classic.jar
log4j-over-slf4j.jar
jcl104-over-slf4j.jar
janino.jar
测试主类:
如果添加Log4j的相关jar包,则控制台输出为:
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/E:/lib/slf4j-log4j12-1.7.9.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/E:/lib/logback-classic-0.9.27.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
[DEBUG] 2016-10-23 15:14:08,549 org.testLogback =======test root=========
[INFO ] 2016-10-23 15:14:08,549 org.testLogback ========test daily level info=========
[WARN ] 2016-10-23 15:14:08,549 org.testLogback ========test warn=========
[ERROR] 2016-10-23 15:14:08,549 org.testLogback ========test error=========
从上面信息可以看出,当有多个StaticLoggerBinder实现时,默认为Log4jLoggerFactory,
去除Log4j的相关jar包,控制输出:
15:24:53,431 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
15:24:53,432 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
15:24:53,432 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file:/F:/Myeclipse/Log/bin/logback.xml]
15:24:53,477 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
15:24:53,494 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
15:24:53,497 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [stdout]
15:24:53,506 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
15:24:53,542 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
15:24:53,543 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [file—debug]
15:24:53,555 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - No compression will be used
15:24:53,555 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - Will use the pattern F:/logback/debug.%d{yyyy-MM-dd}.log for the active file
15:24:53,558 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - The date pattern is 'yyyy-MM-dd' from file name pattern 'F:/logback/debug.%d{yyyy-MM-dd}.log'.
15:24:53,558 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Roll-over at midnight.
15:24:53,560 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Setting initial period to Sun Oct 23 15:24:53 CST 2016
15:24:53,560 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
15:24:53,561 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[file—debug] - Active log file name: F:/logback/debug.2016-10-23.log
15:24:53,561 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[file—debug] - File property is set to [null]
15:24:53,564 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
15:24:53,564 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [file—error]
15:24:53,565 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - No compression will be used
15:24:53,565 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - Will use the pattern F:/logback/error.%d{yyyy-MM-dd}.log for the active file
15:24:53,566 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - The date pattern is 'yyyy-MM-dd' from file name pattern 'F:/logback/error.%d{yyyy-MM-dd}.log'.
15:24:53,566 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Roll-over at midnight.
15:24:53,566 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Setting initial period to Sun Oct 23 15:24:53 CST 2016
15:24:53,566 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
15:24:53,566 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[file—error] - Active log file name: F:/logback/error.2016-10-23.log
15:24:53,566 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[file—error] - File property is set to [null]
15:24:53,566 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
15:24:53,566 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [file-str]
15:24:53,568 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.boolex.JaninoEventEvaluator] for [evaluator] property
15:24:53,910 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - No compression will be used
15:24:53,910 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - Will use the pattern F:/logback/contains.%d{yyyy-MM-dd}.log for the active file
15:24:53,910 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - The date pattern is 'yyyy-MM-dd' from file name pattern 'F:/logback/contains.%d{yyyy-MM-dd}.log'.
15:24:53,910 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Roll-over at midnight.
15:24:53,910 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Setting initial period to Sun Oct 23 15:24:53 CST 2016
15:24:53,910 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
15:24:53,911 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[file-str] - Active log file name: F:/logback/contains.2016-10-23.log
15:24:53,911 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[file-str] - File property is set to [null]
15:24:53,912 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.classic.db.DBAppender]
15:24:53,963 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [db]
15:24:53,968 |-INFO in ch.qos.logback.classic.joran.action.LevelAction - java.sql.Connection level set to DEBUG
15:24:53,968 |-INFO in ch.qos.logback.classic.joran.action.LevelAction - java.sql.Statement level set to DEBUG
15:24:53,968 |-INFO in ch.qos.logback.classic.joran.action.LevelAction - com.ibatis level set to DEBUG
15:24:53,968 |-INFO in ch.qos.logback.classic.joran.action.LevelAction - com.ibatis.common.jdbc.SimpleDataSource level set to DEBUG
15:24:53,968 |-INFO in ch.qos.logback.classic.joran.action.LevelAction - com.ibatis.common.jdbc.ScriptRunner level set to DEBUG
15:24:53,968 |-INFO in ch.qos.logback.classic.joran.action.LevelAction - com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate level set to DEBUG
15:24:53,968 |-INFO in ch.qos.logback.classic.joran.action.LevelAction - com.danga.MemCached level set to INFO
15:24:53,968 |-INFO in ch.qos.logback.classic.joran.action.LevelAction - org.springframework.test level set to DEBUG
15:24:53,968 |-INFO in ch.qos.logback.classic.joran.action.LevelAction - org.apache.struts2 level set to DEBUG
15:24:53,968 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to DEBUG
15:24:53,968 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [stdout] to Logger[ROOT]
15:24:53,970 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [file—debug] to Logger[ROOT]
15:24:53,970 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [file—error] to Logger[ROOT]
15:24:53,970 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [file-str] to Logger[ROOT]
15:24:53,970 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [db] to Logger[ROOT]
2016-10-23 15:24:53,976 [main] DEBUG org.testLogback - =======test root=========
2016-10-23 15:24:53,979 [main] INFO org.testLogback - ========test daily level info=========
2016-10-23 15:24:53,979 [main] WARN org.testLogback - ========test warn=========
2016-10-23 15:24:53,979 [main] ERROR org.testLogback - ========test error=========
去F盘logback文件夹下,可以看到相关日志文件
contains.2016-10-23.log
debug.2016-10-23.log
2016-10-23 15:24:53,976 [main] DEBUG org.testLogback - =======test root=========
error.2016-10-23.log
2016-10-23 15:24:53,979 [main] ERROR org.testLogback - ========test error=========
我的logback.xml文件如下:
总结:
从上面的测试可以看出logback日志,可以根据日志的类别去,输出到不同的文件,不用log4j那样要输出大于等于Appender日志等级的日志。
Logback日志使用详解:http://www.cnblogs.com/davidwang456/p/4448011.html
logback的介绍-配置:http://sunney2010.iteye.com/blog/1404723
slf4j + Logback详解:http://donald-draper.iteye.com/admin/blogs/2332433
需要的jar
slf4j-api.jar
logback-core.jar
logback-classic.jar
log4j-over-slf4j.jar
jcl104-over-slf4j.jar
janino.jar
测试主类:
package org; import org.slf4j.Logger; import org.slf4j.LoggerFactory; public class testLogback { private static Logger log = LoggerFactory.getLogger(testSFL4J.class); public static void main(String[] args) { log.debug("=======test root========="); log.info("========test daily level info========="); log.warn("========test warn========="); log.error("========test error========="); } }
如果添加Log4j的相关jar包,则控制台输出为:
SLF4J: Class path contains multiple SLF4J bindings.
SLF4J: Found binding in [jar:file:/E:/lib/slf4j-log4j12-1.7.9.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: Found binding in [jar:file:/E:/lib/logback-classic-0.9.27.jar!/org/slf4j/impl/StaticLoggerBinder.class]
SLF4J: See http://www.slf4j.org/codes.html#multiple_bindings for an explanation.
SLF4J: Actual binding is of type [org.slf4j.impl.Log4jLoggerFactory]
[DEBUG] 2016-10-23 15:14:08,549 org.testLogback =======test root=========
[INFO ] 2016-10-23 15:14:08,549 org.testLogback ========test daily level info=========
[WARN ] 2016-10-23 15:14:08,549 org.testLogback ========test warn=========
[ERROR] 2016-10-23 15:14:08,549 org.testLogback ========test error=========
从上面信息可以看出,当有多个StaticLoggerBinder实现时,默认为Log4jLoggerFactory,
去除Log4j的相关jar包,控制输出:
15:24:53,431 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback.groovy]
15:24:53,432 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Could NOT find resource [logback-test.xml]
15:24:53,432 |-INFO in ch.qos.logback.classic.LoggerContext[default] - Found resource [logback.xml] at [file:/F:/Myeclipse/Log/bin/logback.xml]
15:24:53,477 |-INFO in ch.qos.logback.classic.joran.action.ConfigurationAction - debug attribute not set
15:24:53,494 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.ConsoleAppender]
15:24:53,497 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [stdout]
15:24:53,506 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
15:24:53,542 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
15:24:53,543 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [file—debug]
15:24:53,555 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - No compression will be used
15:24:53,555 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - Will use the pattern F:/logback/debug.%d{yyyy-MM-dd}.log for the active file
15:24:53,558 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - The date pattern is 'yyyy-MM-dd' from file name pattern 'F:/logback/debug.%d{yyyy-MM-dd}.log'.
15:24:53,558 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Roll-over at midnight.
15:24:53,560 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Setting initial period to Sun Oct 23 15:24:53 CST 2016
15:24:53,560 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
15:24:53,561 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[file—debug] - Active log file name: F:/logback/debug.2016-10-23.log
15:24:53,561 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[file—debug] - File property is set to [null]
15:24:53,564 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
15:24:53,564 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [file—error]
15:24:53,565 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - No compression will be used
15:24:53,565 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - Will use the pattern F:/logback/error.%d{yyyy-MM-dd}.log for the active file
15:24:53,566 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - The date pattern is 'yyyy-MM-dd' from file name pattern 'F:/logback/error.%d{yyyy-MM-dd}.log'.
15:24:53,566 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Roll-over at midnight.
15:24:53,566 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Setting initial period to Sun Oct 23 15:24:53 CST 2016
15:24:53,566 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
15:24:53,566 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[file—error] - Active log file name: F:/logback/error.2016-10-23.log
15:24:53,566 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[file—error] - File property is set to [null]
15:24:53,566 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.core.rolling.RollingFileAppender]
15:24:53,566 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [file-str]
15:24:53,568 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.boolex.JaninoEventEvaluator] for [evaluator] property
15:24:53,910 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - No compression will be used
15:24:53,910 |-INFO in c.q.l.core.rolling.TimeBasedRollingPolicy - Will use the pattern F:/logback/contains.%d{yyyy-MM-dd}.log for the active file
15:24:53,910 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - The date pattern is 'yyyy-MM-dd' from file name pattern 'F:/logback/contains.%d{yyyy-MM-dd}.log'.
15:24:53,910 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Roll-over at midnight.
15:24:53,910 |-INFO in c.q.l.core.rolling.DefaultTimeBasedFileNamingAndTriggeringPolicy - Setting initial period to Sun Oct 23 15:24:53 CST 2016
15:24:53,910 |-INFO in ch.qos.logback.core.joran.action.NestedComplexPropertyIA - Assuming default type [ch.qos.logback.classic.encoder.PatternLayoutEncoder] for [encoder] property
15:24:53,911 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[file-str] - Active log file name: F:/logback/contains.2016-10-23.log
15:24:53,911 |-INFO in ch.qos.logback.core.rolling.RollingFileAppender[file-str] - File property is set to [null]
15:24:53,912 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - About to instantiate appender of type [ch.qos.logback.classic.db.DBAppender]
15:24:53,963 |-INFO in ch.qos.logback.core.joran.action.AppenderAction - Naming appender as [db]
15:24:53,968 |-INFO in ch.qos.logback.classic.joran.action.LevelAction - java.sql.Connection level set to DEBUG
15:24:53,968 |-INFO in ch.qos.logback.classic.joran.action.LevelAction - java.sql.Statement level set to DEBUG
15:24:53,968 |-INFO in ch.qos.logback.classic.joran.action.LevelAction - com.ibatis level set to DEBUG
15:24:53,968 |-INFO in ch.qos.logback.classic.joran.action.LevelAction - com.ibatis.common.jdbc.SimpleDataSource level set to DEBUG
15:24:53,968 |-INFO in ch.qos.logback.classic.joran.action.LevelAction - com.ibatis.common.jdbc.ScriptRunner level set to DEBUG
15:24:53,968 |-INFO in ch.qos.logback.classic.joran.action.LevelAction - com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate level set to DEBUG
15:24:53,968 |-INFO in ch.qos.logback.classic.joran.action.LevelAction - com.danga.MemCached level set to INFO
15:24:53,968 |-INFO in ch.qos.logback.classic.joran.action.LevelAction - org.springframework.test level set to DEBUG
15:24:53,968 |-INFO in ch.qos.logback.classic.joran.action.LevelAction - org.apache.struts2 level set to DEBUG
15:24:53,968 |-INFO in ch.qos.logback.classic.joran.action.RootLoggerAction - Setting level of ROOT logger to DEBUG
15:24:53,968 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [stdout] to Logger[ROOT]
15:24:53,970 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [file—debug] to Logger[ROOT]
15:24:53,970 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [file—error] to Logger[ROOT]
15:24:53,970 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [file-str] to Logger[ROOT]
15:24:53,970 |-INFO in ch.qos.logback.core.joran.action.AppenderRefAction - Attaching appender named [db] to Logger[ROOT]
2016-10-23 15:24:53,976 [main] DEBUG org.testLogback - =======test root=========
2016-10-23 15:24:53,979 [main] INFO org.testLogback - ========test daily level info=========
2016-10-23 15:24:53,979 [main] WARN org.testLogback - ========test warn=========
2016-10-23 15:24:53,979 [main] ERROR org.testLogback - ========test error=========
去F盘logback文件夹下,可以看到相关日志文件
contains.2016-10-23.log
debug.2016-10-23.log
2016-10-23 15:24:53,976 [main] DEBUG org.testLogback - =======test root=========
error.2016-10-23.log
2016-10-23 15:24:53,979 [main] ERROR org.testLogback - ========test error=========
我的logback.xml文件如下:
<?xml version="1.0" encoding="UTF-8"?> <configuration> <!-- 控制台输出 --> <appender name="stdout" class="ch.qos.logback.core.ConsoleAppender"> <encoder> <pattern>%date [%thread] %-5level %logger{80} - %msg%n</pattern> </encoder> </appender> <!-- 时间滚动输出 level为 DEBUG 日志 --> <appender name="file—debug" class="ch.qos.logback.core.rolling.RollingFileAppender"> <filter class="ch.qos.logback.classic.filter.LevelFilter"> <level>DEBUG</level> <onMatch>ACCEPT</onMatch> <onMismatch>DENY </onMismatch> </filter> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <FileNamePattern>F:/logback/debug.%d{yyyy-MM-dd}.log</FileNamePattern> <MaxHistory>30</MaxHistory> </rollingPolicy> <encoder> <pattern>%date [%thread] %-5level %logger{80} - %msg%n</pattern> <charset>UTF-8</charset> </encoder> </appender> <!-- 时间滚动输出 level为 ERROR 日志 --> <appender name="file—error" class="ch.qos.logback.core.rolling.RollingFileAppender"> <filter class="ch.qos.logback.classic.filter.LevelFilter"> <level>ERROR</level> <onMatch>ACCEPT</onMatch> <onMismatch>DENY </onMismatch> </filter> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <FileNamePattern>F:/logback/error.%d{yyyy-MM-dd}.log</FileNamePattern> <MaxHistory>30</MaxHistory> </rollingPolicy> <encoder> <pattern>%date [%thread] %-5level %logger{80} - %msg%n</pattern> <charset>UTF-8</charset> </encoder> </appender> <!-- 特定过滤含有某字符串的日志 --> <appender name="file-str" class="ch.qos.logback.core.rolling.RollingFileAppender"> <filter class="ch.qos.logback.core.filter.EvaluatorFilter"> <evaluator> <expression>message.contains("str")</expression> </evaluator> <onMatch>ACCEPT</onMatch> <onMismatch>DENY</onMismatch> </filter> <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> <FileNamePattern>F:/logback/contains.%d{yyyy-MM-dd}.log </FileNamePattern> <MaxHistory>30</MaxHistory> </rollingPolicy> <encoder> <pattern>%date [%thread] %-5level %logger{80} - %msg%n</pattern> </encoder> </appender> <!-- 数据库输出 --> <appender name="db" class="ch.qos.logback.classic.db.DBAppender"> <connectionSource class="ch.qos.logback.core.db.DriverManagerConnectionSource"> <driverClass>com.mysql.jdbc.Driver</driverClass> <url>jdbc:mysql://localhost:3306/test</url> <user>root</user> <password>123456</password> </connectionSource> </appender> <logger name="java.sql.Connection"> <level value="DEBUG" /> </logger> <logger name="java.sql.Statement"> <level value="DEBUG" /> </logger> <logger name="com.ibatis"> <level value="DEBUG" /> </logger> <logger name="com.ibatis.common.jdbc.SimpleDataSource"> <level value="DEBUG" /> </logger> <logger name="com.ibatis.common.jdbc.ScriptRunner"> <level value="DEBUG" /> </logger> <logger name="com.ibatis.sqlmap.engine.impl.SqlMapClientDelegate"> <level value="DEBUG" /> </logger> <logger name="com.danga.MemCached"> <level value="INFO" /> </logger> <logger name="org.springframework.test"> <level value="DEBUG" /> </logger> <logger name="org.apache.struts2"> <level value="DEBUG" /> </logger> <root level="DEBUG"> <appender-ref ref="stdout" /> <appender-ref ref="file—debug" /> <appender-ref ref="file—error" /> <appender-ref ref="file-str" /> <appender-ref ref="db" /> </root> </configuration>
总结:
从上面的测试可以看出logback日志,可以根据日志的类别去,输出到不同的文件,不用log4j那样要输出大于等于Appender日志等级的日志。
发表评论
-
一次服务器事故处理过程及教训
2017-02-24 18:50 1169java虚拟机内存查看相关 ... -
slf4j + Logback详解
2016-10-23 19:41 1311Log4j初始化详解:http://donald-draper ... -
slf4j + Log4j 详解
2016-10-23 19:40 1766Log4j初始化详解:http://donald-draper ... -
sfl4j与log4j使用
2016-10-23 11:24 2437slf4j-api、slf4j-log4j12以及log4j之 ... -
Log4j日志输出详解
2016-10-23 00:46 2857Log4j初始化详解:http://donald-draper ... -
Log4j初始化详解
2016-10-22 22:36 4007java中volatile关键字的含义:http://www. ... -
log4j的使用
2016-10-22 11:56 630Log4j使用教程:http://www.codeceo.co ... -
Spring集成log4j,日志初始化过程详解
2016-06-22 17:41 7780以前研究过slf4j-log4j的使用,但具体初始化过程不是很 ...
相关推荐
在IT行业中,日志记录是系统调试、故障排查和性能分析的重要工具。本文将深入探讨“调试日志之slf4j+...文档《复件 日志系统.docx》可能包含了更多关于如何配置和使用SLF4J+Logback的详细信息,建议进一步查阅学习。
总的来说,"log4j-slf4j+logback1.3.0"的组合提供了一个强大、灵活的日志解决方案,允许开发者使用统一的API进行日志记录,同时利用Logback的高性能和丰富特性。通过正确配置这些组件,开发者可以轻松管理和优化Java...
https://github.com/tomcat-slf4j-logback/tomcat-slf4j-logback上的jar与源码,网络不好,下载不易,特此分享。包括: logback-1.2.3.zip Tomcat7.0.82\tomcat-juli-7.0.82-slf4j-1.7.25-logback-1.2.3.zip Tomcat...
本篇将详细介绍SLF4J和Logback的使用,以及它们在实际开发中的重要性。 首先,SLF4J的主要目标是为各种日志框架提供一个简单的抽象,这样应用程序就可以在部署时动态地绑定到任何兼容的实现。SLF4J提供了类似于`...
但对于公共类库或大规模应用来说,使用SLF4J + Logback是非常值得推荐的。 总之,SLF4J + Logback为Java开发者提供了一套强大、灵活且高效的日志解决方案。无论是对于初学者还是经验丰富的开发者,了解并掌握这套...
SLF4J(Simple Logging Facade for Java)和Logback是Java日志处理中的两个重要组件,...通过对SLF4J接口的使用和Logback的细致配置,开发者可以更好地监控和分析应用程序的行为,同时保持代码的可移植性和可维护性。
今天我们将聚焦两个流行的日志框架——SLF4J(Simple Logging Facade for Java)和Logback,以及它们与Log4j和Commons-Logging的对比。 SLF4J是一个接口层的日志框架,它提供一个统一的API,允许用户在运行时插入...
在使用SLF4J和Logback时,你需要引入相应的JAR文件。这些JAR文件通常包括SLF4J API(如`slf4j-api-*.jar`)、Logback核心库(如`logback-core-*.jar`)、Logback经典库(如`logback-classic-*.jar`)以及任何其他...
SSM(Spring、SpringMVC、MyBatis)与Apache Shiro、SLF4J以及Logback是Java Web开发中的重要框架和工具,它们在构建安全、高效且可维护的Web应用方面起着关键作用。这里我们将深入探讨这些技术的核心概念、功能以及...
本文将通过一个配置实例,详细介绍如何在项目中集成和使用SLF4J与Logback。 首先,我们需要在项目的类路径下添加SLF4J和Logback的相关依赖。通常,这包括`slf4j-api.jar`(SLF4J API)、`logback-classic.jar`...
本文将详细介绍如何使用SLF4J与Logback来输出应用程序的日志,并提供必要的配置和依赖知识。 1. **SLF4J介绍** SLF4J提供了一种统一的日志接口,使得开发者可以在不改变代码的情况下切换不同的日志实现,如Log4j、...
SLF4J允许开发者在部署时插入所需的日志实现,比如logback、log4j等,这使得项目的可移植性和灵活性大大增强。 Logback是另一个关键组件,它是由log4j的创始人Ceki Gülcü创建的。Logback是目前广泛使用的日志框架...
为了使用SLF4J结合Logback进行日志记录,你需要以下JAR文件: - `slf4j-api-1.4.3.jar`:SLF4J API,必不可少。 - `logback-core.jar`:Logback的核心包。 - `logback-classic.jar`:Logback的经典模块,包含SLF4J的...
综上所述,Slf4j与Logback的结合使用可以为Java应用程序提供强大的日志管理能力。通过合理的配置和测试,我们可以确保日志系统既满足调试需求,又不拖累应用性能。在实际开发中,理解并熟练运用这些工具是非常重要的...
SLF4J(Simple Logging Facade for Java)和Logback是Java开发中广泛使用的日志处理框架。SLF4J提供了一个抽象层,允许开发者在运行时选择合适的日志实现,而Logback则是SLF4J的一个具体实现,它以其高效、灵活和...
使用 SLF4J 和 Logback 进行日志记录配置的主要目的是: 1. 为 Spring 的开发提供了一个更快速更广泛的入门方法。 2. 使用默认方式实现快速开发。 3. 提供项目所需的一些非功能特性,如嵌入式服务器、安全、心跳...
Tomcat SLF4J Logback是tomcat的替代产品,它允许所有内部日志记录全部使用我们喜欢的slf4j / logback库。 注意 从logback 1.1.7开始,不再需要在server.xml中包含${catalina.home}来进行logback访问。 我们还重新...
【SLF4J(Simple Logging Facade for Java)】是一个日志门面,为各种日志框架如log4j、Logback提供一个统一的接口。SLF4J允许开发者在部署时选择合适的日志实现,只需更换绑定的日志实现库即可。这使得项目具有更好...
janino-2.3.17.jar jcl-over-slf4j-1.6.1.jar log4j-1.2.8.jar logback-access-0.9.24.jar logback-classic-0.9.24.jar logback-core-0.9.24.jar ... slf4j-1.6.1+logback-0.9.24.rar slf4j-api-1.6.1.jar
On Java 8 中用到的日志包,SLF4J+Logback。