log4j

记一次项目上线后Log4j2不输出日志的坑

…衆ロ難τιáo~ 提交于 2020-01-27 22:19:54
公司项目采用了Log4j2来输出日志,在开发环境和测试环境下均可以输出日志,但在生成环境就没有日志输出。开始毫无头绪,后来通过不断的排查,终于解决了这个问题。在此记录下该问题的解决过程,便于后续查阅。 一、发现问题 */ /*--> */ 开发环境打印日志但生产环境不打印日志这个问题比较棘手。一直找不到原因,后面突然想到在启动的时候打印信息肯定会有所不同。通过在 2 个环境启动同一个项目的控制台打印信息对比有了以下的发现: (1) 出现了 SL4J 的警告信息,都是提示包冲突 Multiple bindings were found on the class path (2) 但是仔细观察发现了 加载这两个冲突的 jar 包的顺序不同 ,具体见下图: */ /*--> */ ①开发环境日志冲突jar包加载顺序图 */ /*--> */ 防止图失效,我把文字复制过来了 SLF4J:Class path contains mutiple SLF4J bindings SLF4J:Found binding in[jar:file:/WEB-INF/lib/log4j-slf4j-impl-2.6.6.jar!/org/slf4j/impl/StaticLoggerBider.class] SLF4J:Found binding in[jar:file:/WEB-INF/lib

Java中的日志框架

别说谁变了你拦得住时间么 提交于 2020-01-26 16:16:39
需求 使用日志框架有三点需求: 1、期望日志能保存在文件中,方便时候排错。 2、开发环境的日志记录会更多方便调试。 3、生产环境需要记录重要的信息。 Log4j 可用于普通maven项目,也可以用于springboot项目。 Log4j提供了简单的API调用,强大的日志格式定义以及灵活的扩展性。 可以自定义Appender来满足日志输出的需求。 日志级别 从低到高 DEBUG INFO WARN ERROR FATAL pom依赖 <!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-core --> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-core</artifactId> <version>2.8.2</version> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.logging.log4j/log4j-api --> <dependency> <groupId>org.apache.logging.log4j</groupId> <artifactId>log4j-api</artifactId>

log4j settings in Jetty

不想你离开。 提交于 2020-01-25 20:16:31
问题 I have a java webapp that uses log4j to log messages. This webapp is a wrapper around a jar file that I have written. When I run my webapp through the built-in Jetty from Eclipse, my JAR's logs (LOG.info(...) messages) are printed out just fine. Now, I have downloaded a standalone instance of Jetty and have run my web app from there. With the default log4j settings packaged with Jetty, I am not able to see ANY logs from my JAR. I only see the Jetty logs and the webapp's logs. I have found the

eclipse搭建ssm框架

[亡魂溺海] 提交于 2020-01-25 10:09:14
新建数据库ssm 建立数据库表 user CREATE TABLE `user` (   `id` int(11) NOT NULL AUTO_INCREMENT ,   `sex` varchar(255) NULL ,   `name` varchar(255) NULL ,   PRIMARY KEY (`id`) ); 新建一个 Java web工程 SSM,目录结构如下 下面挨个看下配置文件 conf.properties配置详情 url=jdbc:mysql://localhost:3306/ssm?useUnicode=true&characterEncoding=utf-8&autoReconnect=true driver=com.mysql.jdbc.Driver username=root password=root log4j.properties配置详情 log4j.rootLogger=info, live, file log4j.logger.org.springframework=ERROR —log4j.logger.org.logicalcobwebs.proxool=ERROR log4j.appender.live=org.apache.log4j.ConsoleAppender log4j.appender.live.Target

How to log all values set in MDC in json format using log4j.properties file in log4j 1.2

霸气de小男生 提交于 2020-01-25 07:54:05
问题 I want to display all values set in MDC in log file in json format in log4j 1.2 version. This is third party's log4j.properties file I'm modifying so I can't change anything other than this log4j.properties file, I mean I can't add any other dependency like to help this log4j to support MDC and json format. I can print values using %X{PARAMETER_NAME} but can't get all MDC values at once. log4j.appender.ReportsExecutionLog = org.apache.log4j.RollingFileAppender log4j.appender

MDC to log entire dynamic message, irrespective of no of entries in MDC

人盡茶涼 提交于 2020-01-25 06:51:29
问题 I want to use MDC for logging for that I'm doing MDC.put("ReportName", "IOR_Report"); MDC.put("ReportJNDI", JNDI_NAME.getValue()); log.info("Report logger working"); And added below entry in log4j.properties and it's printing correct ReportName="My ReportName" JNDI=MYJNDI log4j.appender.REPORTSLOG = org.apache.log4j.RollingFileAppender log4j.appender.REPORTSLOG.layout = org.apache.log4j.PatternLayout log4j.appender.REPORTSLOG.File = ../logs/ReportLog.log log4j.appender.REPORTSLOG.Threshold

MDC to log entire dynamic message, irrespective of no of entries in MDC

前提是你 提交于 2020-01-25 06:51:17
问题 I want to use MDC for logging for that I'm doing MDC.put("ReportName", "IOR_Report"); MDC.put("ReportJNDI", JNDI_NAME.getValue()); log.info("Report logger working"); And added below entry in log4j.properties and it's printing correct ReportName="My ReportName" JNDI=MYJNDI log4j.appender.REPORTSLOG = org.apache.log4j.RollingFileAppender log4j.appender.REPORTSLOG.layout = org.apache.log4j.PatternLayout log4j.appender.REPORTSLOG.File = ../logs/ReportLog.log log4j.appender.REPORTSLOG.Threshold

SSM+crud集成

三世轮回 提交于 2020-01-25 05:38:36
SSM : SSM(Spring+SpringMVC+MyBatis)框架集由Spring、MyBatis两个开源框架整合而成(SpringMVC是Spring中的部分内容)。常作为数据源较简单的web项目的框架。 1.1Spring Spring就像是整个项目中装配bean的大工厂,在配置文件中可以指定使用特定的参数去调用实体类的构造方法来实例化对象。也可以称之为项目中的粘合剂。   Spring的核心思想是IoC(控制反转),即不再需要程序员去显式地 new 一个对象,而是让Spring框架帮你来完成这一切。 1.2SpringMVC SpringMVC在项目中拦截用户请求,它的核心Servlet即DispatcherServlet承担中介或是前台这样的职责,将用户请求通过HandlerMapping去匹配Controller,Controller就是具体对应请求所执行的操作。SpringMVC相当于SSH框架中struts。 1.3mybatis mybatis是对jdbc的封装,它让数据库底层操作变的透明。mybatis的操作都是围绕一个sqlSessionFactory实例展开的。mybatis通过配置文件关联到各实体类的Mapper文件,Mapper文件中配置了每个类对数据库所需进行的sql语句映射。在每次与数据库交互时

Is it possible to use format modifiers for two conversion characters combined?

偶尔善良 提交于 2020-01-24 05:22:10
问题 I know how to output classname and methodname with log4j, both fields can be aligned and padded separately, e.g. this pattern: [%d{ISO8601}] %-5p %-10C{1}:%-10M %m%n produces something like: [2012-09-20 08:25:12,111] WARN Class :method Logtext1 which should align [2012-09-20 08:25:12,111] WARN ClassTwo :methodName Logtext2 which should align This will align the logged text (in most cases), but the classname and methodname are ugly spaced. So what I would like to output is something like:

Spring Boot 日志配置

假装没事ソ 提交于 2020-01-23 21:44:35
Spring Boot支持 JavaUtil Logging、 Log4J、 Log4J2和 Logback作为日志框架,无论使用哪种日志框架, Spring Boot已为当前使用日志框架的控制台输出及文件输出做好了配置,默认情况下, Spring Boot使用 Logback作为日志框架。 配置 logback(官方推荐使用) 配置日志文件 spring boot 默认会加载 classpath:logback-spring.xml 或者 classpath:logback-spring.groovy。 如需要自定义文件名称,在 application.properties 中配置 logging.config 选项即可。 在 src/main/resources 下创建 logback-spring.xml 文件,内容如下: <?xml version="1.0" encoding="UTF-8"?> <configuration> <!-- 文件输出格式 --> <property name="PATTERN" value="%-12(%d{yyyy-MM-dd HH:mm:ss.SSS}) |-%-5level [%thread] %c [%L] -| %msg%n" /> <!-- test文件路径 --> <property name="TEST_FILE_PATH"