logger记录在控制台显示,但是在日志输出文件中不显示问题排查
场景:
代码中存在使用logger.info输出数据到指定的文件中,然后用logstash去收集需要的数据插入到es中。
现象:
logger.info输出的记录打断点在控制台上显示,但是在配置的日志输出文件中却找不到日志输出的内容。
log4j配置
如下:
打断点排查
logger.info在控制台有打印输出,但是配置的日志输出文件中却什么也没有
14:53:02.737 [http-nio-8082-exec-3] INFO com.gisquest.platform.modules.funcmgr.web.FuncGroupItemController - {"opertion":"删除菜单分组\u201c在办办件1\u201d","ip":"192.168.100.88","staffname":"系统管理员","model":"菜单定制","id":"分组id:5b2a9f1e-828e-11ed-971c-3c7c3fba0919","userid":"8c7d3682-c080-4d4a-947f-af08e64576a2","url":"http://GisqPlatformDesigner-Rest.gisquest.com:8082/GisqPlatformDesigner-Rest/service//funcmgr/delete-group-item/5b2a9f1e-828e-11ed-971c-3c7c3fba0919","mac":"","object":"分组id:5b2a9f1e-828e-11ed-971c-3c7c3fba0919;分组名称:在办办件1;父分组:菜单管理","username":"admin"}
原因分析:
分析一:按道理讲我的日志输出在控制能看到了,按理说也会写入platform.log配置的文件中去。
分析二:jar包冲突 网上提示说是日志包冲突了,我看了一下项目中的日志包如下,多出来了两个logback的包。
logback-core-1.2.3.jar
logback-class-1.2.3.jarlog4j-1.2.17.jar
log4j-api-2.17.2,jar
log4j-core-2.17.2.jarslf4-api-1.17.10.jar
slf4j-kig4j12-1.7.10.jar
jcl-over-slf4j-1.7.10.jar
jul-to-slf4j-1.7.10.jar
排查一:logback的包是那个依赖中引进去的?
借助idea工具使用mvn dependency:tree 命令将依赖树打印出来,
定位:发现logback是gisquest-log-client-Spring4:jar中被引入进去了。
] +- com.gisquest.cloud:gisquest-log-client-Spring4:jar:1.0:compile
[INFO] | \- com.gisquest.cloud:gisquest-log-client-common:jar:1.0:compile
[INFO] | +- com.alibaba:fastjson:jar:1.2.83:compile
[INFO] | +- org.projectlombok:lombok:jar:1.18.10:compile
[INFO] | +- com.gisquest.cloud:gisquest-log-common:jar:1.0:compile
[INFO] | | +- org.codehaus.jackson:jackson-mapper-asl:jar:1.9.12:compile
[INFO] | | | \- org.codehaus.jackson:jackson-core-asl:jar:1.9.12:compile
[INFO] | | \- cn.hutool:hutool-core:jar:5.6.6:compile
[INFO] | +- com.gisquest.cloud:gisquest-log-autoscan:jar:1.0:compile
[INFO] | | \- com.gisquest.cloud:gisquest-log-entity:jar:1.0:compile
[INFO] | | +- com.baomidou:mybatis-plus-annotation:jar:3.4.2:compile
[INFO] | | \- io.swagger:swagger-annotations:jar:1.5.22:compile
[INFO] | +- ch.qos.logback:logback-core:jar:1.2.3:compile
[INFO] | +- ch.qos.logback:logback-classic:jar:1.2.3:compile
[INFO] | \- cn.hutool:hutool-all:jar:5.8.3:compile
[INFO] +- com.gisquest:GisqPlatform-Apollo:jar:1.0.0:compile
[INFO] | +- com.ctrip.framework.apollo:apollo-client:jar:1.3.0:compile
[INFO] | | \- com.google.inject:guice:jar:4.1.0:compile
[INFO] | | +- javax.inject:javax.inject:jar:1:compile
[INFO] | | \- aopalliance:aopalliance:jar:1.0:compile
[INFO] | \- com.ctrip.framework.apollo:apollo-core:jar:1.3.0:compile
[INFO] | \- com.google.code.gson:gson:jar:2.8.0:compile
[INFO] \- com.gisquest.wcspsdk:wcspsdk-server:jar:2.3.0.4-RELEASE:compile
解决方式:将该包中的logback排除掉
<!-- 日志中心客户端 -->
<dependency>
<groupId>com.gisquest.cloud</groupId>
<artifactId>gisquest-log-client-Spring4</artifactId>
<version>1.0</version>
<exclusions>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId>
</exclusion>
<exclusion>
<groupId>ch.qos.logback</groupId>
<artifactId>logback-core</artifactId>
</exclusion>
</exclusions>
</dependency>
排除后再次测试,一切正常
2022-12-23 15:00:13,529 INFO [platform.modules.funcmgr.web.FuncGroupItemController] - {"opertion":"删除菜单分组\u201c在办办件1\u201d","ip":"192.168.100.88","staffname":"系统管理员","model":"菜单定制","id":"分组id:5b2a9f1e-828e-11ed-971c-3c7c3fba0919","userid":"8c7d3682-c080-4d4a-947f-af08e64576a2","url":"http://GisqPlatformDesigner-Rest.gisquest.com:8082/GisqPlatformDesigner-Rest/service//funcmgr/delete-group-item/5b2a9f1e-828e-11ed-971c-3c7c3fba0919","mac":"","object":"分组id:5b2a9f1e-828e-11ed-971c-3c7c3fba0919;分组名称:在办办件1;父分组:菜单管理","username":"admin"}
参考:
彻底解决SLF4J的日志冲突的问题_zy苦行僧的博客-CSDN博客_日志冲突