简体   繁体   中英

How to disable Restlet access logging when using JEE version in Servlet Container like Tomcat?

The Restlet framework documentation touts it's ability to run stand-alone via it's Server class and using the jse library build or to run in a Servlet container like Tomcat using the jee library build.

The library helpfully produces two types of log records , code related log records for debugging and errors and access related log records that look like this:

20-Dec-2018 12:33:01.723 INFO [http-nio-8088-exec-52] org.restlet.engine.log.LogFilter.afterHandle 2018-12-20   12:33:01    0:0:0:0:0:0:0:1 -   0:0:0:0:0:0:0:1 8088    POST    /WebApp/route   -   204 0   647 11619   http://localhost:8088   PostmanRuntime/7.4.0    -

This is helpful in stand-alone mode with the -jse build where Engine#setLogLevel(...) exists. I find this Apache httpd like logging to be extra noise when using the -jse build inside of a Tomcat container where I already have a separate access log. Unfortunately Engine#setLogLevel doesn't exist in the JEE build.

Using the simple Apache Tomcat Restlet JEE example code , where is the ideal place to disable the Restlet access log?

After testing different things, using Logger.getLogger("org.restlet").setLevel(Level.WARNING) was the only thing that reliably suppressed the Restlet access log messages. I tried org.restlet.engine, org.restlet.engine.og, and org.resetlet.engine.log.LogFilter and various component access methods, none suppressed the message. I'm not sure if I'm not suppressing more than I really wanted. It seems that if Engine#setLevel isn't available in JEE, then access logging should be default suppressed in JEE.

package my.package.space;

import java.util.logging.Level;
import java.util.logging.Logger;
import org.restlet.Application;
import org.restlet.Restlet; // from org.restlet.jee artifact version 2.3.12
import org.restlet.routing.Router;

public class MyJeeApplication extends Application {

    /**
     * Creates a root Restlet that will receive all incoming calls.
     */
    @Override
    public synchronized Restlet createInboundRoot() {
        // Create a router Restlet that routes each call to a new instance of HelloWorldResource.
        Router router = new Router(getContext());
        // Set restlet log level to warning to suppress 
        // INFO org.restlet.engine.log.LogFilter.afterHandle access log messages
        Logger.getLogger("org.restlet").setLevel(Level.WARNING);
        // Defines only one route
        //router.attach("/hello", HelloWorldResource.class);
        router.attachDefault(HelloWorldResource.class);

        return router;
    }

}

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