How to disable logging in Restlet 2.0?

I just want to disable restyling logging in stdout / stderr in my project and forward all Restlete entries through the SLF4J facade provided by org.restlet.ext.slf4j. Is there an easy way to do this?

+2
source share
6 answers

You must first configure SLF4J to intercept all Restlet calls in the java.util.logging API and map them to calls in the SLF4J facade API. You just do this by putting jul-to-slf4j.jar in your classpath, as @Bruno noted.

Secondly, you must configure the SLF4J facade to redirect its API calls to the logging implementation to actually generate the log message. To use the Logback logging implementation, you put logback-classic.jar in your classpath.

Finally, you must configure the selected logging implementation. If you use Logback, you can configure the logging level of individual Loggers using XML .

We use SLF4J with Restlet, and we really like the way SLF4J combines all the different logging APIs into one. It is very cute.

Edit April 29th, 2019: Be sure to check out comments by @NaftuliKay and @stempler.

+3
source

This is what I did to disable logging to STDERR and forward the log to log4j. This is basically just the base class all wrestlers are based on. It will install the log4j bridge, find the console handler, and disable it. It works for me, but it may not be the best solution, so if someone has a better solution that does not require an external configuration, please let me know.

public class CommonRestlet extends Application { static { // Install logging bridge (JUL -> LOG4J) SLF4JBridgeHandler.install(); // Disable annoying console logging of requests.. Logger logger = Logger.getLogger("org.restlet"); for (Handler handler : logger.getParent().getHandlers()) { // Find the console handler if (handler.getClass().equals(java.util.logging.ConsoleHandler.class)) { // set level to SEVERE. We could disable it completely with // a custom filter but this is good enough. handler.setLevel(Level.SEVERE); } } } // Other common stuff here... } 

Dependency in pom.xml

  <dependency> <groupId>org.slf4j</groupId> <artifactId>jul-to-slf4j</artifactId> <version>1.6.1</version> </dependency> <dependency> <groupId>org.slf4j</groupId> <artifactId>slf4j-log4j12</artifactId> <version>1.6.1</version> <exclusions> <exclusion> <groupId>log4j</groupId> <artifactId>log4j</artifactId> </exclusion> </exclusions> </dependency> 
+3
source

I managed to disable annoying Restlet logging with:

 Component component = new Component(); // Disable damn log component.setLogService(new org.restlet.service.LogService(false)); 

...

+1
source

I try to use the jul-to-slf4j bridge , but you can get other configurations as described in the Restlet Wiki .

0
source

Something seems wrong here: if you have the org.restlet.ext.slf4j.jar, slf4j-api.jar, logback-core.jar and logback-classic.jar file associated with it, you already have everything that you need to disable logging in sdout and stderr. Just change the configuration file (logback.xml) so as not to add to them.

In this configuration, a restayl uses slf4j "natively" and the usual slf4j configuration is used.

In addition, org.restlet.ext.slf4j.jar eliminates the need for jul-to-slf4j.jar, which will entail a serious performance hit.

0
source

Software configuration

 Engine.setRestletLogLevel(Level.OFF); 

Details: http://restlet.com/learn/guide/2.2/editions/jse/logging

Starting with version 2.1, you can now programmatically change the log level using the static methods Set # SetLogLevel (...) and SetRestletLogLevel (...). It is also possible to enable a selective call log by setting the Request # loggable property or overriding the LogService # isLoggable (Request) method.

0
source

All Articles