I'm currently observing that a 3rd party library (namely restfb) is using java.util.logging and I'm seeing those logs end up in STDOUT even though I don't have an SLF4J console appender configured in my logback.xml. I also have the jul-to-slf4j bridge in my classpath. Does the jul-to-slf4j bridge only log to the appenders configured by logback when the bridge is installed or does it also log to stdout?
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
I use SLF4J and new Postgres driver 42.0.0
According changelog it use java.util.logging
To have driver logs it is enough:
Add jul-to-slf4j bridge:
Add in logback.xml (logback-test.xml)
Add in code
My solution :
placing jul-to-slf4j on your app libs or glassfish libs, these redirect JUL to SLF4J (and thus in my case to LOG4J)
then for Jersey, you could do something like :
the last config is to avoid to be polluted by other loggers
As mentioned in the javadocs for SLF4JBridgeHandler, you get either install SLF4JBridgeHandler programmatically by invoking:
or via logging.properties
As for performance, the section on jul-to-slf4j bridge discusses this issue. In essence, since you are already using logback, enabling the LevelChangePropagator should yield good performance regardless of the load.
Solution that seems nice (considering the circumstances with the JUL bridging) and works for me, since I only have to write everything in the logback.groovy file.
(If you are not using logback.groovy configuration or logback at all, of course you have to put the logic part into some class (e.g. like
class MyApp { static { /* log init code here */ } ... }
).)src/logback.groovy:
(recommended to be used by me since you can react with Java code vars/functions as you can see in here with, e.g. SLF4JBridgeHandler or the log dir regarding webappDirName)
(left the file complete since it gives a better impression how everything can be setup or as a staring template)
(may be relevant to somebody - my env: slf4j 1.7.5, logback 1.1.2, groovy 2.1.9)
You need to call
SLF4JBridgeHandler.install()
. You also need to enable all log levels at the root logger (reason in excerpt below) in java.util.logging and remove the default console appender.The whole process can be accomplished like so
You can set the level to something higher than finest for performance reasons, but you won't be able to turn those logs on without enabling them in
java.util.logging
first (for the reason mentioned above in the excerpt).