Restlet:如何抑制服务器请求日志消息

时间:2013-05-03 19:52:50

标签: logging restlet

我使用Restlet 2.1.2创建了一个简单的REST服务器,它运行良好。每个POST或GET请求都会导致Restlet发出以下格式的日志消息:

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    -

有很多请求,应用程序收集这些消息并不重要。问题:

  • 该消息发出的是什么类?我试图通过Restlet源代码来查找它,但没有运气。
  • 这些消息正被发送到stdout。如何将它们直接写入文件?
  • 如何配置它以便仅在响应状态不是200?
  • 时生成此类消息

非常感谢任何信息。

PS:我发现了一些似乎相关的链接,虽然我还没有弄清楚究竟需要做些什么。我将这些留在这里供将来参考。

1 个答案:

答案 0 :(得分:1)

只需创建并设置一个NullLogService即表示所有请求都不可记录:

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

然后将其设置为您的日志服务:

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();    
}