dongtan7351 2015-11-24 07:24
浏览 26
已采纳

在go-json-rest中关闭访问记录器

I am trying to write REST services in Go. As there are different frameworks for writing REST service in Go, we would like to do some performance testing before choosing the framework.

Currently I did a sample using go-json-rest. But when I execute this sample REST request, I see the following logs printed in my terminal.

24/Nov/2015:12:30:35 +0530 200 29μs "GET /countries HTTP/1.1" - "Java/1.8.0_45"

This logging will take some time and impact my performance report. How can I switch of this logging?

  • 写回答

1条回答 默认 最新

  • du248227 2015-11-25 14:27
    关注

    You should know that it's AccessLogApacheMiddleware that controls your logging, and DefaultDevStack contains the AccessLogApacheMiddleware.

    Two ways to prevent logging:

    1. You can use a predefined variable like DefaultCommonStack which doesn't contain the AccessLogApacheMiddleware;
    2. Construct your own ...Middlewares. Since the Use function is a Variadic Functions, which pass the multiple middlewares into the function. If you don't need AccessLogApacheMiddleware, you just ignore it. It gives you more power to control whatever middlewares you like.

    e.g.

    api := rest.NewApi()
    api.Use(&rest.TimerMiddleware{},
        &rest.RecorderMiddleware{},
        &rest.PoweredByMiddleware{},
        &rest.RecoverMiddleware{})
    

    May this be helpful.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?