简体   繁体   中英

can I configure Java logging to make use of Spring Boot logging?

My use case is as follows. I'm developing a large spring based application and we are using spring boot logging throughout. However, for various reasons I need to use a third-party library that uses java.util.Logger in its internals. This causes the two separate loggers to both send their output to our console.

I've found many examples on how to configure spring boot logging to use java logging as its output, but I haven't been able to determine how to go the other way.

The library in question - JLibModbus - includes API access to set it's logging level or to turn it off, but I don't see any way to actually tell it to use a different logger. Presumably this should be possible. I'm hoping that someone else has already done this.

(Actually I'm working in Kotlin, not Java, but any answer that works in one I should be able to convert to the other.)

If I understand you correctly, you want to configure the logging of a lib which uses Java Util Logging.

Spring Boot comes already with a managed dependency which helps you to fix your issue.

Please add or verify that you've already added the JUL to SLF4J bridge:

<dependency>
    <groupId>org.slf4j</groupId>
    <artifactId>jul-to-slf4j</artifactId>
</dependency>

Please check also, that you put your logger configurations in the correct config file , especially referencing:

  • Logback – logback-spring.xml, …
  • Log4j2 – log4j2-spring.xml, …
  • JDK (Java Util Logging) – logging.properties

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM