Logback是由log4j创始人Ceki Gülcü设计的又一个开源日志组件。
logback.xml
- <?xml version="1.0" encoding="UTF-8"?> <!-- Reference Manual http://logback.qos.ch/manual/index.html -->
- <configuration>
- <!-- LEVEL:TRACE, DEBUG, INFO, WARN, ERROR, ALL 和 OFF -->
- <!-- 控制台输出 -->
- <appender name="stdout" class="ch.qos.logback.core.ConsoleAppender">
- <!-- encoder 可以指定字符集,对于中文输出有意义 -->
- <encoder charset="UTF-8">
- <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern>
- </encoder>
- </appender>
- <!-- 每日最多生成10个文件,可以通过这些文件查看系统工作状态 -->
- <!--
- <appender name="RollingFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
- <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
- <level>TRACE</level>
- </filter>
- <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy">
- <fileNamePattern>${log.root}/WEB-INF/logs/trace-%d{yyyy-MM-dd}.log</fileNamePattern>
- <maxHistory>10</maxHistory>
- </rollingPolicy>
- <encoder>
- <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern>
- </encoder>
- </appender>
- -->
- <!-- 下面这段注释的代码可以在日志文件超过 5MB 时进行归档,并且归档文件后缀只要是 .zip 或 .gz 就会自动
- 压缩日志归档 -->
- <appender name="InfoFileZip" class="ch.qos.logback.core.rolling.RollingFileAppender">
- <file>${log.root}/WEB-INF/logs/info.log</file>
- <filter class="ch.qos.logback.classic.filter.ThresholdFilter">
- <level>INFO</level>
- </filter>
- <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
- <fileNamePattern>${log.root}/WEB-INF/logs/bak/info.%i.log.zip</fileNamePattern>
- <minIndex>1</minIndex>
- <maxIndex>10</maxIndex>
- </rollingPolicy>
- <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
- <maxFileSize>10MB</maxFileSize>
- </triggeringPolicy>
- <encoder>
- <pattern>%d{HH:mm:ss.SSS} [%thread] %-5level %logger - %msg%n</pattern>
- </encoder>
- </appender>
- <!-- 时间滚动输出 level为 ERROR 日志 -->
- <appender name="ErrorFile" class="ch.qos.logback.core.rolling.RollingFileAppender">
- <filter class="ch.qos.logback.classic.filter.LevelFilter">
- <level>ERROR</level>
- <OnMismatch>DENY</OnMismatch>
- <OnMatch>ACCEPT</OnMatch>
- </filter>
- <File>${log.root}/WEB-INF/logs/error.log</File>
- <rollingPolicy class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
- <FileNamePattern>${log.root}/WEB-INF/logs/error.log.%i.bak</FileNamePattern>
- <MinIndex>1</MinIndex>
- <MaxIndex>3</MaxIndex>
- </rollingPolicy>
- <triggeringPolicy class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
- <MaxFileSize>100MB</MaxFileSize>
- </triggeringPolicy>
- <encoder>
- <Pattern>%d{yyyy-MM-dd HH:mm:ss.SSS} [%thread] %-5level %logger{36} - %msg
- %n</Pattern>
- </encoder>
- </appender>
- <!-- 输出到控制台和文件,可定义更多的 Appender,默认配置 -->
- <root level="DEBUG">
- <appender-ref ref="stdout" />
- </root>
- <!-- com.sysmaster包配置日志规则 -->
- <logger name="com.sysmaster" level="INFO" additivity="false">
- <appender-ref ref="stdout"/>
- <appender-ref ref="InfoFileZip"/>
- <appender-ref ref="ErrorFile"/>
- </logger>
- <!--为com.sysmaster.po.ResourcePO类配置日志规则 -->
- <!--
- <logger name="com.sysmaster.po.ResourcePO" level="INFO" additivity="false">
- <appender-ref ref="STDOUT"/>
- </logger>
- -->
- <!-- 下面配置一些第三方包的日志过滤级别,用于避免刷屏 -->
- <!--
- <logger name="org.hibernate" level="WARN"/>
- <logger name="org.springframework" level="WARN"/>
- <logger name="com.opensymphony" level="WARN"/>
- <logger name="org.apache" level="WARN"/>
- -->
- <!-- 为 Hibernate 定制日志规则 -->
- <logger name="org.hibernate.type.descriptor.sql.BasicBinder" level="TRACE"/>
- <logger name="org.hibernate.type.descriptor.sql.BasicExtractor" level="DEBUG"/>
- <logger name="org.hibernate.SQL" level="DEBUG"/>
- <logger name="org.hibernate.engine.QueryParameters" level="DEBUG"/>
- <logger name="org.hibernate.engine.query.HQLQueryPlan" level="DEBUG"/>
- </configuration>
LogbackConfigListener.java
- package com.sysmaster.util.logback;
- import javax.servlet.ServletContextEvent;
- import javax.servlet.ServletContextListener;
- /**
- * 用于启用logback日志
- *
- */
- public class LogbackConfigListener implements ServletContextListener {
- public void contextInitialized(ServletContextEvent event) {
- LogbackWebConfigurer.initLogging(event.getServletContext());
- }
- public void contextDestroyed(ServletContextEvent event) {
- LogbackWebConfigurer.shutdownLogging(event.getServletContext());
- }
- }
LogbackConfigurer.java
- package com.sysmaster.util.logback;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.net.URL;
- import org.slf4j.LoggerFactory;
- import org.springframework.util.ResourceUtils;
- import org.springframework.util.SystemPropertyUtils;
- import ch.qos.logback.classic.LoggerContext;
- import ch.qos.logback.classic.joran.JoranConfigurator;
- import ch.qos.logback.core.joran.spi.JoranException;
- /**
- *
- * 用于读取logback的配置文件,可以直接用spring->log4j的代码修改
- *
- */
- public abstract class LogbackConfigurer
- {
- public static final String CLASSPATH_URL_PREFIX = "classpath:";
- public static final String XML_FILE_EXTENSION = ".xml";
- private static LoggerContext lc = (LoggerContext) LoggerFactory.getILoggerFactory();
- private static JoranConfigurator configurator = new JoranConfigurator();
- public static void initLogging(String location) throws FileNotFoundException {
- String resolvedLocation = SystemPropertyUtils.resolvePlaceholders(location);
- URL url = ResourceUtils.getURL(resolvedLocation);
- if (resolvedLocation.toLowerCase().endsWith(XML_FILE_EXTENSION)) {
- configurator.setContext(lc);
- lc.reset();
- try {
- configurator.doConfigure(url);
- } catch (JoranException ex) {
- throw new FileNotFoundException(url.getPath());
- }
- lc.start();
- }
- }
- public static void shutdownLogging() {
- lc.stop();
- }
- public static void setWorkingDirSystemProperty(String key) {
- System.setProperty(key, new File("").getAbsolutePath());
- }
- }
LogbackWebConfigurer.java
- package com.sysmaster.util.logback;
- import java.io.FileNotFoundException;
- import javax.servlet.ServletContext;
- import org.springframework.util.ResourceUtils;
- import org.springframework.util.SystemPropertyUtils;
- import org.springframework.web.util.WebUtils;
- /**
- *
- * 用于读取logback的WEB配置文件,可以直接用spring->log4j的代码修改
- *
- */
- public abstract class LogbackWebConfigurer
- {
- public static final String CONFIG_LOCATION_PARAM = "logbackConfigLocation";
- public static final String REFRESH_INTERVAL_PARAM = "logbackRefreshInterval";
- public static final String EXPOSE_WEB_APP_ROOT_PARAM = "logbackExposeWebAppRoot";
- public static void initLogging(ServletContext servletContext) {
- if (exposeWebAppRoot(servletContext)) {
- WebUtils.setWebAppRootSystemProperty(servletContext);
- }
- String location = servletContext.getInitParameter(CONFIG_LOCATION_PARAM);
- if (location != null) {
- try {
- if (!ResourceUtils.isUrl(location)) {
- location = SystemPropertyUtils.resolvePlaceholders(location);
- location = WebUtils.getRealPath(servletContext, location);
- }
- servletContext.log("从 [" + location + "]初始化logback的配置");
- LogbackConfigurer.initLogging(location);
- } catch (FileNotFoundException ex) {
- throw new IllegalArgumentException("无效的 'logbackConfigLocation' 配置参数,请检查web.xml中的logbackConfigLocation参数值前是否有classpat字样: " + ex.getMessage());
- }
- }
- }
- public static void shutdownLogging(ServletContext servletContext) {
- servletContext.log("关闭logback");
- try {
- LogbackConfigurer.shutdownLogging();
- } finally {
- if (exposeWebAppRoot(servletContext)) {
- WebUtils.removeWebAppRootSystemProperty(servletContext);
- }
- }
- }
- private static boolean exposeWebAppRoot(ServletContext servletContext) {
- String exposeWebAppRootParam = servletContext.getInitParameter(EXPOSE_WEB_APP_ROOT_PARAM);
- return (exposeWebAppRootParam == null || Boolean.valueOf(exposeWebAppRootParam));
- }
- }
转:http://star77266989.iteye.com/blog/2112113
相关推荐
logback相关jar包 lobback.xml例子 测试代码.java
logback1.1.2配置文件,所需jar包及源代码
MATLAB实验一二 数值计算
Java毕业设计-ssm基于SSM的英语学习网站的设计与实现演示录像(高分期末大作业)
平安保险-智富人生A的计算
MATLAB实验五六 图像相关应用
AUTOSAR_SRS_FreeRunningTimer.pdf
onnxruntime-1.7.1-cp39-cp39-linux_armv7l.whl.zip
qwen2 colab代码
885 - Space Scooter.mpd
该资源是软考-信息系统项目管理师 高级考试 相关的论文资源,《论项目整体管理》。项目基于本人在实际的工作中的最佳实践,以软件工程实施为背景,从 制定项目章程、制定项目管理计划、指导与管理项目工作、管理项目知识、监控项目工作、实施整体变更控制、结束项目或阶段的角度介绍了项目资源管理的方法论。 理论框架基于最新的 PMBOK 第6版,核心理念是项目管理是一个综合性工程,不仅要重点关注项目范围、进度、成本、质量四要素,更要关注整体管理、资源管理、风险管理、干系人管理、沟通管理、采购管理、绩效域管理等。在项目新兴实践方面还要注意与敏捷管理的结合,因为现在的大型项目更多使用的是混合型开发模式,主体功能采用预测型生命周期,而分支功能或非主体功能可能采用敏捷生命周期,只有综合运用领导力技能和项目管理的最佳实践,才能使项目最终走向成功。
AUTOSAR_SWS_IntrusionDetectionSystemManager.pdf
python模块onnxruntime版本
AUTOSAR_SRS_SAEJ1939.pdf
AUTOSAR_SRS_CryptoStack.pdf
瑞士轮
cfx
纸片战争Beta压缩试行代码
python模块onnxruntime版本
Java毕业设计-ssm汽车租赁管理演示录像(高分期末大作业)