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.

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

报告相同问题?

悬赏问题

  • ¥15 基于51单片机的厨房煤气泄露检测报警系统设计
  • ¥15 路易威登官网 里边的参数逆向
  • ¥15 Arduino无法同时连接多个hx711模块,如何解决?
  • ¥50 需求一个up主付费课程
  • ¥20 模型在y分布之外的数据上预测能力不好如何解决
  • ¥15 processing提取音乐节奏
  • ¥15 gg加速器加速游戏时,提示不是x86架构
  • ¥15 python按要求编写程序
  • ¥15 Python输入字符串转化为列表排序具体见图,严格按照输入
  • ¥20 XP系统在重新启动后进不去桌面,一直黑屏。