New Jersey Magazine Level New LoggingFeature

I am trying to enter with Jersey 2.23. Starting with this version, the LoggingFilter class LoggingFilter deprecated, as can be here, for example, here: https://jersey.java.net/documentation/latest/logging_chapter.html . Therefore I have to use LoggingFeature . That operation was not register with the ResourceConfig method, as explained in this documentation. But in the end, the property method worked:

 client.property(LoggingFeature.LOGGING_FEATURE_LOGGER_LEVEL_SERVER, "WARN"); 

This prints each message as a warning. Unfortunately, this is not registered anywhere (at least I could not find anything) which values ​​are valid. Obviously, this must be a String, because I get a log message that there is no way to convert the value to String when I try to do anything else than String. Now I want to register these messages with a TRACE level, and I cannot find a suitable String for this. For example, "TRACE" and "FINE" did not work, in these cases nothing was registered. I should mention that I use Log4j2 along with Slf4jBridgeHandler because Jersey uses JUL.

+6
source share
1 answer

I struggled with this myself for several hours before finally uncovering the "secret" today.

This is somewhat counterintuitive, but the level you set with LOGGING_FEATURE_LOGGER_LEVEL_SERVER is actually the minimum level that the server logger must be set to print your logs. I assumed, based on the name, that this sets the actual level of the registrar - meaning that setting it to FINER or FINEST will increase the output volume. Instead, it is simply “turning off” the registration if a certain level is not reached.

As an example, if you set it to WARNING , you will see the logs if the server / client is configured to print at least WARNING . Levels defined by java.util.logging:

SEVERE (highest value)
WARNING
INFO
Config
FINE
FINER
FINEST (lowest value)

Therefore, setting it to WARNING (literal WARN does not work for me in 2.23.1), you will see the logs, because by default logging is usually at the INFO level.

An alternative solution is to change the default logging level in your logging.properties file, which is usually located in $JAVA_HOME/jre/lib/logging.properties . For example, you can make the following changes to the file, and you will no longer need to set any special properties in your code:

 java.util.logging.ConsoleHandler.level = FINEST org.glassfish.jersey.test.JerseyTest.level = FINEST 

The obvious downside of this is that it will affect everything you run from this JDK / JRE. There are ways to override this default location and use an alternative logging.properties file, but it depends on how you execute your code, so I will give you a study based on your circumstances.

An example is this thread, which explains how to do this when using Maven: Logging level in maven surefire

+8
source

All Articles