【问题标题】:Restlet: how to suppress server request log messagesRestlet:如何抑制服务器请求日志消息
【发布时间】:2013-05-03 19:52:50
【问题描述】:

我使用 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 源代码 grep 来找到它,但没有运气。
  • 这些消息正在发送到标准输出。如何将它们直接写入文件?
  • 如何配置它以便仅在响应状态不是 200 时才生成此类消息?

非常感谢您提供任何信息。

PS:我发现了一些似乎相关的链接,尽管我还没有弄清楚到底需要做什么。我将把这些留在这里以供将来参考。

【问题讨论】:

    标签: logging restlet


    【解决方案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();    
    }
    

    【讨论】:

    • 谢谢一百万!关于只记录 HTTP 返回码不是 200 的响应,我想我可以从 isLoggable 的参数中提取它?
    • 似乎这是一个不错的方法
    猜你喜欢
    • 1970-01-01
    • 2018-02-13
    • 2015-07-15
    • 1970-01-01
    • 1970-01-01
    • 2018-01-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多