Logback
官网:https://logback.qos.ch/
Logback分为三个模块:logback-core、logback-classic 和 logback-access。
logback-core 模块为其他两个模块奠定了基础。
logback-classic 模块可以同化为 log4j 1.x 的显着改进版本。此外,logback-classic 原生实现了SLF4J API,因此您可以轻松地在 logback 和其他日志框架(例如 log4j 1.x 或 java.util.logging (JUL))之间来回切换。
logback-access 模块与 Tomcat 和 Jetty 等 Servlet 容器集成,以提供 HTTP 访问日志功能。请注意,您可以轻松地在 logback-core 之上构建自己的模块。
简单使用logback:slf4j-api-1.7.26.jar logback-core-1.2.3.jar logback-classic-1.2.3.jar
slf4j-api下载地址:https://www.slf4j.org/download.html
logback-core 和 logback-classic下载地址:https://logback.qos.ch/download.html
logback.xml配置-放在src目录下:
<?xml version="1.0" encoding="UTF-8"?> <configuration debug="false"> <!-- Where are log files --> <property name="LOG_HOME" value="./" /> <!-- Output to Console --> <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender"> <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> <!--%d:date,%thread:thread,%-5level:error/debug/info... %msg:message,%n:new line --> <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} - %msg%n</pattern> </encoder> </appender> <!-- Output to File --> <appender name="FILE" class="ch.qos.logback.core.rolling.RollingFileAppender"> <rollingPolicy class="ch.qos.logback.core.rolling.SizeAndTimeBasedRollingPolicy"> <fileNamePattern>${LOG_HOME}/log.%d{yyyy-MM-dd}.%i.log </fileNamePattern> <maxFileSize>1000MB</maxFileSize> <MaxHistory>60</MaxHistory> </rollingPolicy> <encoder class="ch.qos.logback.classic.encoder.PatternLayoutEncoder"> <!--%d:date,%thread:thread,%-5level:error/debug/info... %msg:message,%n:new line --> <pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{50} -%msg%n</pattern> </encoder> </appender> <!-- log level TRACE, DEBUG, INFO, WARN, ERROR, ALL and OFF,default:DEBUG. --> <root level="INFO"> <appender-ref ref="STDOUT" /> <appender-ref ref="FILE" /> </root> </configuration>