sag
sag

Reputation: 5451

Turn off access logger in 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?

Upvotes: 0

Views: 252

Answers (1)

holys
holys

Reputation: 14769

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.

Upvotes: 1

Related Questions