起因:构建独立版本debezuim使用时,日志一直打印debug信息。
原因:包冲突问题,进行排包操作。
参考log4j日志级别配置完成后不生效 系统一直打印debug日志_log4j不起作用-CSDN博客
1、application.properties
logging.config=classpath:log4j.properties
2、log4j.properties 配置打印error日志,因依赖jar中已打印debug,所以升级打印级别,识别有效信息。
# 设置根日志级别
#log4j.rootLogger=DEBUG, stdout, R
log4j.rootLogger=ERROR, stdout, R# 标准输出Appender配置
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n# 文件输出Appender配置
log4j.appender.R=org.apache.log4j.DailyRollingFileAppender
log4j.appender.R.File=logs/app.log
log4j.appender.R.layout=org.apache.log4j.PatternLayout
log4j.appender.R.layout.ConversionPattern=%d{yyyy-MM-dd HH:mm:ss} %-5p %c{1}:%L - %m%n
3、查看系统mvn依赖树:
mvn dependency:tree
首先 mvn dependency:tree 检查,打印如下:
确实存在logback包,在Springboot自带的依赖里。
artifact-transfer-0.11.0.jar (128 kB at 148 kB/s)
[INFO] com:hs:jar:0.0.1-SNAPSHOT
[INFO] +- org.slf4j:slf4j-api:jar:1.7.25:compile
[INFO] +- com.alibaba:fastjson:jar:1.2.75:compile
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:2.2.13.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot-starter:jar:2.2.13.RELEASE:compile
[INFO] | | +- org.springframework.boot:spring-boot:jar:2.2.13.RELEASE:compile
[INFO] | | +- org.springframework.boot:spring-boot-autoconfigure:jar:2.2.13.RELEASE:compile
[INFO] | | +- org.springframework.boot:spring-boot-starter-logging:jar:2.2.13.RELEASE:compile
[INFO] | | | +- ch.qos.logback:logback-classic:jar:1.2.3:compile
[INFO] | | | | \- ch.qos.logback:logback-core:jar:1.2.3:compile
[INFO] | | | +- org.apache.logging.log4j:log4j-to-slf4j:jar:2.12.1:compile
[INFO] | | | | \- org.apache.logging.log4j:log4j-api:jar:2.12.1:compile
[INFO] | | | \- org.slf4j:jul-to-slf4j:jar:1.7.30:compile
[INFO] | | +- jakarta.annotation:jakarta.annotation-api:jar:1.3.5:compile
[INFO] | | +- org.springframework:spring-core:jar:5.2.12.RELEASE:compile
[INFO] | | | \- org.springframework:spring-jcl:jar:5.2.12.RELEASE:compile
[INFO] | | \- org.yaml:snakeyaml:jar:1.25:runtime
[INFO] | +- org.springframework.boot:spring-boot-starter-json:jar:2.2.13.RELEASE:compile
[INFO] | | +- com.fasterxml.jackson.core:jackson-databind:jar:2.10.5.1:compile
[INFO] | | | \- com.fasterxml.jackson.core:jackson-annotations:jar:2.10.5:compile
[INFO] | | +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.10.5:compile
[INFO] | | +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.10.5:compile
[INFO] | | \- com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.10.5:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-tomcat:jar:2.2.13.RELEASE:compile
[INFO] | | +- org.apache.tomcat.embed:tomcat-embed-core:jar:9.0.41:compile
[INFO] | | +- org.apache.tomcat.embed:tomcat-embed-el:jar:9.0.41:compile
[INFO] | | \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:9.0.41:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-validation:jar:2.2.13.RELEASE:compile
[INFO] | | +- jakarta.validation:jakarta.validation-api:jar:2.0.2:compile
[INFO] | | \- org.hibernate.validator:hibernate-validator:jar:6.0.22.Final:compile
[INFO] | | +- org.jboss.logging:jboss-logging:jar:3.4.1.Final:compile
[INFO] | | \- com.fasterxml:classmate:jar:1.5.1:compile
[INFO] | +- org.springframework:spring-web:jar:5.2.12.RELEASE:compile
[INFO] | | \- org.springframework:spring-beans:jar:5.2.12.RELEASE:compile
[INFO] | \- org.springframework:spring-webmvc:jar:5.2.12.RELEASE:compile
[INFO] | +- org.springframework:spring-aop:jar:5.2.12.RELEASE:compile
[INFO] | +- org.springframework:spring-context:jar:5.2.12.RELEASE:compile
[INFO] | \- org.springframework:spring-expression:jar:5.2.12.RELEASE:compile
[INFO] +- io.debezium:debezium-api:jar:1.4.2.Final:compile
[INFO] +- io.debezium:debezium-embedded:jar:1.4.2.Final:compile
[INFO] | +- io.debezium:debezium-core:jar:1.4.2.Final:compile
[INFO] | | +- com.fasterxml.jackson.core:jackson-core:jar:2.10.5:compile
[INFO] | | +- org.reflections:reflections:jar:0.9.12:compile
[INFO] | | | \- org.javassist:javassist:jar:3.26.0-GA:compile
[INFO] | | \- com.google.guava:guava:jar:30.0-jre:compile
[INFO] | | +- com.google.guava:failureaccess:jar:1.0.1:compile
[INFO] | | \- com.google.guava:listenablefuture:jar:9999.0-empty-to-avoid-conflict-with-guava:compile
[INFO] | +- org.apache.kafka:connect-api:jar:2.3.1:compile
[INFO] | | +- org.apache.kafka:kafka-clients:jar:2.3.1:compile
[INFO] | | | +- com.github.luben:zstd-jni:jar:1.4.0-1:compile
[INFO] | | | +- org.lz4:lz4-java:jar:1.6.0:compile
[INFO] | | | \- org.xerial.snappy:snappy-java:jar:1.1.7.3:compile
[INFO] | | \- javax.ws.rs:javax.ws.rs-api:jar:2.1.1:compile
[INFO] | +- org.apache.kafka:connect-runtime:jar:2.3.1:compile
[INFO] | | +- org.apache.kafka:kafka-tools:jar:2.3.1:compile
[INFO] | | | +- org.apache.kafka:kafka-log4j-appender:jar:2.3.1:compile
[INFO] | | | | \- org.slf4j:slf4j-log4j12:jar:1.7.30:compile
[INFO] | | | | \- log4j:log4j:jar:1.2.17:compile
[INFO] | | | \- net.sourceforge.argparse4j:argparse4j:jar:0.7.0:compile
[INFO] | | +- org.apache.kafka:connect-transforms:jar:2.3.1:compile
[INFO] | | +- com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:jar:2.10.5:compile
[INFO] | | | +- com.fasterxml.jackson.jaxrs:jackson-jaxrs-base:jar:2.10.5:compile
[INFO] | | | \- com.fasterxml.jackson.module:jackson-module-jaxb-annotations:jar:2.10.5:compile
[INFO] | | | +- jakarta.xml.bind:jakarta.xml.bind-api:jar:2.3.3:compile
[INFO] | | | \- jakarta.activation:jakarta.activation-api:jar:1.2.2:compile
[INFO] | | +- org.glassfish.jersey.containers:jersey-container-servlet:jar:2.29.1:compile
[INFO] | | | +- org.glassfish.jersey.containers:jersey-container-servlet-core:jar:2.29.1:compile
[INFO] | | | | \- org.glassfish.hk2.external:jakarta.inject:jar:2.6.1:compile
[INFO] | | | +- org.glassfish.jersey.core:jersey-common:jar:2.29.1:compile
[INFO] | | | | \- org.glassfish.hk2:osgi-resource-locator:jar:1.0.3:compile
[INFO] | | | +- org.glassfish.jersey.core:jersey-server:jar:2.29.1:compile
[INFO] | | | | +- org.glassfish.jersey.core:jersey-client:jar:2.29.1:compile
[INFO] | | | | \- org.glassfish.jersey.media:jersey-media-jaxb:jar:2.29.1:compile
[INFO] | | | \- jakarta.ws.rs:jakarta.ws.rs-api:jar:2.1.6:compile
[INFO] | | +- org.glassfish.jersey.inject:jersey-hk2:jar:2.29.1:compile
[INFO] | | | \- org.glassfish.hk2:hk2-locator:jar:2.6.1:compile
[INFO] | | | +- org.glassfish.hk2.external:aopalliance-repackaged:jar:2.6.1:compile
[INFO] | | | +- org.glassfish.hk2:hk2-api:jar:2.6.1:compile
[INFO] | | | \- org.glassfish.hk2:hk2-utils:jar:2.6.1:compile
[INFO] | | +- javax.xml.bind:jaxb-api:jar:2.3.1:compile
[INFO] | | | \- javax.activation:javax.activation-api:jar:1.2.0:compile
[INFO] | | +- javax.activation:activation:jar:1.1.1:compile
[INFO] | | +- org.eclipse.jetty:jetty-server:jar:9.4.35.v20201120:compile
[INFO] | | | +- javax.servlet:javax.servlet-api:jar:4.0.1:compile
[INFO] | | | +- org.eclipse.jetty:jetty-http:jar:9.4.35.v20201120:compile
[INFO] | | | \- org.eclipse.jetty:jetty-io:jar:9.4.35.v20201120:compile
[INFO] | | +- org.eclipse.jetty:jetty-servlet:jar:9.4.35.v20201120:compile
[INFO] | | | +- org.eclipse.jetty:jetty-security:jar:9.4.35.v20201120:compile
[INFO] | | | \- org.eclipse.jetty:jetty-util-ajax:jar:9.4.35.v20201120:compile
[INFO] | | +- org.eclipse.jetty:jetty-servlets:jar:9.4.35.v20201120:compile
[INFO] | | | +- org.eclipse.jetty:jetty-continuation:jar:9.4.35.v20201120:compile
[INFO] | | | \- org.eclipse.jetty:jetty-util:jar:9.4.35.v20201120:compile
[INFO] | | +- org.eclipse.jetty:jetty-client:jar:9.4.35.v20201120:compile
[INFO] | | \- org.apache.maven:maven-artifact:jar:3.6.1:compile
[INFO] | | +- org.codehaus.plexus:plexus-utils:jar:3.2.0:compile
[INFO] | | \- org.apache.commons:commons-lang3:jar:3.9:compile
[INFO] | +- org.apache.kafka:connect-json:jar:2.3.1:compile
[INFO] | \- org.apache.kafka:connect-file:jar:2.3.1:compile
[INFO] +- io.debezium:debezium-connector-mysql:jar:1.4.2.Final:compile
[INFO] | +- io.debezium:debezium-ddl-parser:jar:1.4.2.Final:compile
[INFO] | | \- org.antlr:antlr4-runtime:jar:4.7.2:compile
[INFO] | +- com.zendesk:mysql-binlog-connector-java:jar:0.23.3:compile
[INFO] | \- mysql:mysql-connector-java:jar:8.0.22:compile
[INFO] \- org.projectlombok:lombok:jar:1.18.16:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 14.589 s
[INFO] Finished at: 2024-12-24T09:57:41+08:00
[INFO] ------------------------------------------------------------------------
通过mvn dependency:tree 查下系统的依赖树,检查下是否存在logback的依赖包,如果发现有logback-classic logback-core之类的包,从依赖树的上层过滤掉之后再看下,系统日志打印级别就会正常了
4、pom中操作排包 exclusions标签:
<dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId><!--排除,不包含--><exclusions><exclusion><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-logging</artifactId></exclusion></exclusions> </dependency>
相关maven命令和排包 可以参考
maven:又遇到maven jar包冲突了?比较常见的处理方法及避坑-腾讯云开发者社区-腾讯云
后续:
排包后打印:成功去除logback.jar。
E:\work_space\shiwei&@hussar830\shiwei_gitlab\debezuim_new>mvn dependency:tree
[INFO] Scanning for projects...
[INFO]
[INFO] -------------------------------< com:hs >-------------------------------
[INFO] Building hs 0.0.1-SNAPSHOT
[INFO] --------------------------------[ jar ]---------------------------------
[INFO]
[INFO] --- maven-dependency-plugin:3.1.2:tree (default-cli) @ hs ---
[INFO] com:hs:jar:0.0.1-SNAPSHOT
[INFO] +- com.alibaba:fastjson:jar:1.2.75:compile
[INFO] +- org.springframework.boot:spring-boot-starter-web:jar:2.2.13.RELEASE:compile
[INFO] | +- org.springframework.boot:spring-boot-starter:jar:2.2.13.RELEASE:compile
[INFO] | | +- org.springframework.boot:spring-boot:jar:2.2.13.RELEASE:compile
[INFO] | | +- org.springframework.boot:spring-boot-autoconfigure:jar:2.2.13.RELEASE:compile
[INFO] | | +- jakarta.annotation:jakarta.annotation-api:jar:1.3.5:compile
[INFO] | | +- org.springframework:spring-core:jar:5.2.12.RELEASE:compile
[INFO] | | | \- org.springframework:spring-jcl:jar:5.2.12.RELEASE:compile
[INFO] | | \- org.yaml:snakeyaml:jar:1.25:runtime
[INFO] | +- org.springframework.boot:spring-boot-starter-json:jar:2.2.13.RELEASE:compile
[INFO] | | +- com.fasterxml.jackson.core:jackson-databind:jar:2.10.5.1:compile
[INFO] | | | \- com.fasterxml.jackson.core:jackson-annotations:jar:2.10.5:compile
[INFO] | | +- com.fasterxml.jackson.datatype:jackson-datatype-jdk8:jar:2.10.5:compile
[INFO] | | +- com.fasterxml.jackson.datatype:jackson-datatype-jsr310:jar:2.10.5:compile
[INFO] | | \- com.fasterxml.jackson.module:jackson-module-parameter-names:jar:2.10.5:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-tomcat:jar:2.2.13.RELEASE:compile
[INFO] | | +- org.apache.tomcat.embed:tomcat-embed-core:jar:9.0.41:compile
[INFO] | | +- org.apache.tomcat.embed:tomcat-embed-el:jar:9.0.41:compile
[INFO] | | \- org.apache.tomcat.embed:tomcat-embed-websocket:jar:9.0.41:compile
[INFO] | +- org.springframework.boot:spring-boot-starter-validation:jar:2.2.13.RELEASE:compile
[INFO] | | +- jakarta.validation:jakarta.validation-api:jar:2.0.2:compile
[INFO] | | \- org.hibernate.validator:hibernate-validator:jar:6.0.22.Final:compile
[INFO] | | +- org.jboss.logging:jboss-logging:jar:3.4.1.Final:compile
[INFO] | | \- com.fasterxml:classmate:jar:1.5.1:compile
[INFO] | +- org.springframework:spring-web:jar:5.2.12.RELEASE:compile
[INFO] | | \- org.springframework:spring-beans:jar:5.2.12.RELEASE:compile
[INFO] | \- org.springframework:spring-webmvc:jar:5.2.12.RELEASE:compile
[INFO] | +- org.springframework:spring-aop:jar:5.2.12.RELEASE:compile
[INFO] | +- org.springframework:spring-context:jar:5.2.12.RELEASE:compile
[INFO] | \- org.springframework:spring-expression:jar:5.2.12.RELEASE:compile
[INFO] +- io.debezium:debezium-api:jar:1.4.2.Final:compile
[INFO] | \- org.slf4j:slf4j-api:jar:1.7.30:compile
[INFO] +- io.debezium:debezium-embedded:jar:1.4.2.Final:compile
[INFO] | +- io.debezium:debezium-core:jar:1.4.2.Final:compile
[INFO] | | +- com.fasterxml.jackson.core:jackson-core:jar:2.10.5:compile
[INFO] | | +- org.reflections:reflections:jar:0.9.12:compile
[INFO] | | | \- org.javassist:javassist:jar:3.26.0-GA:compile
[INFO] | | \- com.google.guava:guava:jar:30.0-jre:compile
[INFO] | | +- com.google.guava:failureaccess:jar:1.0.1:compile
[INFO] | | \- com.google.guava:listenablefuture:jar:9999.0-empty-to-avoid-conflict-with-guava:compile
[INFO] | +- org.apache.kafka:connect-api:jar:2.3.1:compile
[INFO] | | +- org.apache.kafka:kafka-clients:jar:2.3.1:compile
[INFO] | | | +- com.github.luben:zstd-jni:jar:1.4.0-1:compile
[INFO] | | | +- org.lz4:lz4-java:jar:1.6.0:compile
[INFO] | | | \- org.xerial.snappy:snappy-java:jar:1.1.7.3:compile
[INFO] | | \- javax.ws.rs:javax.ws.rs-api:jar:2.1.1:compile
[INFO] | +- org.apache.kafka:connect-runtime:jar:2.3.1:compile
[INFO] | | +- org.apache.kafka:kafka-tools:jar:2.3.1:compile
[INFO] | | | +- org.apache.kafka:kafka-log4j-appender:jar:2.3.1:compile
[INFO] | | | | \- org.slf4j:slf4j-log4j12:jar:1.7.30:compile
[INFO] | | | | \- log4j:log4j:jar:1.2.17:compile
[INFO] | | | \- net.sourceforge.argparse4j:argparse4j:jar:0.7.0:compile
[INFO] | | +- org.apache.kafka:connect-transforms:jar:2.3.1:compile
[INFO] | | +- com.fasterxml.jackson.jaxrs:jackson-jaxrs-json-provider:jar:2.10.5:compile
[INFO] | | | +- com.fasterxml.jackson.jaxrs:jackson-jaxrs-base:jar:2.10.5:compile
[INFO] | | | \- com.fasterxml.jackson.module:jackson-module-jaxb-annotations:jar:2.10.5:compile
[INFO] | | | +- jakarta.xml.bind:jakarta.xml.bind-api:jar:2.3.3:compile
[INFO] | | | \- jakarta.activation:jakarta.activation-api:jar:1.2.2:compile
[INFO] | | +- org.glassfish.jersey.containers:jersey-container-servlet:jar:2.29.1:compile
[INFO] | | | +- org.glassfish.jersey.containers:jersey-container-servlet-core:jar:2.29.1:compile
[INFO] | | | | \- org.glassfish.hk2.external:jakarta.inject:jar:2.6.1:compile
[INFO] | | | +- org.glassfish.jersey.core:jersey-common:jar:2.29.1:compile
[INFO] | | | | \- org.glassfish.hk2:osgi-resource-locator:jar:1.0.3:compile
[INFO] | | | +- org.glassfish.jersey.core:jersey-server:jar:2.29.1:compile
[INFO] | | | | +- org.glassfish.jersey.core:jersey-client:jar:2.29.1:compile
[INFO] | | | | \- org.glassfish.jersey.media:jersey-media-jaxb:jar:2.29.1:compile
[INFO] | | | \- jakarta.ws.rs:jakarta.ws.rs-api:jar:2.1.6:compile
[INFO] | | +- org.glassfish.jersey.inject:jersey-hk2:jar:2.29.1:compile
[INFO] | | | \- org.glassfish.hk2:hk2-locator:jar:2.6.1:compile
[INFO] | | | +- org.glassfish.hk2.external:aopalliance-repackaged:jar:2.6.1:compile
[INFO] | | | +- org.glassfish.hk2:hk2-api:jar:2.6.1:compile
[INFO] | | | \- org.glassfish.hk2:hk2-utils:jar:2.6.1:compile
[INFO] | | +- javax.xml.bind:jaxb-api:jar:2.3.1:compile
[INFO] | | | \- javax.activation:javax.activation-api:jar:1.2.0:compile
[INFO] | | +- javax.activation:activation:jar:1.1.1:compile
[INFO] | | +- org.eclipse.jetty:jetty-server:jar:9.4.35.v20201120:compile
[INFO] | | | +- javax.servlet:javax.servlet-api:jar:4.0.1:compile
[INFO] | | | +- org.eclipse.jetty:jetty-http:jar:9.4.35.v20201120:compile
[INFO] | | | \- org.eclipse.jetty:jetty-io:jar:9.4.35.v20201120:compile
[INFO] | | +- org.eclipse.jetty:jetty-servlet:jar:9.4.35.v20201120:compile
[INFO] | | | +- org.eclipse.jetty:jetty-security:jar:9.4.35.v20201120:compile
[INFO] | | | \- org.eclipse.jetty:jetty-util-ajax:jar:9.4.35.v20201120:compile
[INFO] | | +- org.eclipse.jetty:jetty-servlets:jar:9.4.35.v20201120:compile
[INFO] | | | +- org.eclipse.jetty:jetty-continuation:jar:9.4.35.v20201120:compile
[INFO] | | | \- org.eclipse.jetty:jetty-util:jar:9.4.35.v20201120:compile
[INFO] | | +- org.eclipse.jetty:jetty-client:jar:9.4.35.v20201120:compile
[INFO] | | \- org.apache.maven:maven-artifact:jar:3.6.1:compile
[INFO] | | +- org.codehaus.plexus:plexus-utils:jar:3.2.0:compile
[INFO] | | \- org.apache.commons:commons-lang3:jar:3.9:compile
[INFO] | +- org.apache.kafka:connect-json:jar:2.3.1:compile
[INFO] | \- org.apache.kafka:connect-file:jar:2.3.1:compile
[INFO] +- io.debezium:debezium-connector-mysql:jar:1.4.2.Final:compile
[INFO] | +- io.debezium:debezium-ddl-parser:jar:1.4.2.Final:compile
[INFO] | | \- org.antlr:antlr4-runtime:jar:4.7.2:compile
[INFO] | +- com.zendesk:mysql-binlog-connector-java:jar:0.23.3:compile
[INFO] | \- mysql:mysql-connector-java:jar:8.0.22:compile
[INFO] \- org.projectlombok:lombok:jar:1.18.16:compile
[INFO] ------------------------------------------------------------------------
[INFO] BUILD SUCCESS
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 1.365 s
[INFO] Finished at: 2024-12-24T10:13:40+08:00
[INFO] ------------------------------------------------------------------------
附带:如何找排除的包,从树形依赖关系里就能看到子父关系。