Search code examples
loggingrestlet

Restlet: how to suppress server request log messages


I have created a simple REST server using Restlet 2.1.2 and it is working very well. Every POST or GET request causes Restlet to emit a log message of the form:

2013-05-02  19:44:39    127.0.0.1   -   -   8081    POST    /rest/dispatch  -   200 -   -   21  http://127.0.0.1:8081Restlet-Framework/2.1.2    -

There are a lot of requests and it is not important for the application to collect those messages. Questions:

  • From what class is that message emitted? I have tried to grep through the Restlet source code to find it, but no luck.
  • Those messages are being sent to stdout. How can I write them directly to a file?
  • How can I configure it so that such messages are generated only if the response status is something other than 200 ?

Thanks a lot for any information.

PS: I found some links which seem relevant, although I haven't yet puzzled out exactly what needs to be done. I'll leave these here for future reference.


Solution

  • Simply create and set a NullLogService that says all requests are not loggable:

    public class NullLogService extends LogService 
    {
        @Override
        public boolean isLoggable(Request request) {
            return false;
        }
    }
    

    and then set that as your log service:

    public static void main(String[] args) throws Exception {  
        Component component = new Component();
        component.getServers().add(Protocol.HTTP, 8082);
    
        Application application = new RestletTestResource();  
    
        component.getDefaultHost().attach(application);  
        component.setLogService(new NullLogService());
        component.start();    
    }