mozilla-services/pushgo — pull request #86 by kitcambridge (2014-09-16 05:31:40+00:00)
Title: Refactor logging

This pull request adds logging for all incoming requests, clarifies existing log levels, and adds a `HekaLogger` implementation for compatibility with the Cloud Services [logging standard](https://mana.mozilla.org/wiki/display/CLOUDSERVICES/Logging+Standard).

* HekaLogger` logs Protocol Buffer (`HekaProtobuf`) or JSON (`HekaJSON`)-encoded log messages to standard output.
* `TextLogger` replaces `StdOutLogger` for logging output using @jrconlin's human-readable format (see jrconlin/FindMyDevice@65c0f33684e4d01a9e70d02d497d17668aa2fe3b).
* All incoming requests and `Worker`s are tagged with the `X-Request-Id` header. This is a convention used by [Heroku](https://devcenter.heroku.com/articles/http-request-id), [restify](http://mcavage.me/node-restify/), etc., and allows correlating log lines for the same request. This value is sent in the `t` log field.
* `LogHandler` wraps `http.Handler`s and logs request replies. `logResponseWriter` wraps `http.ResponseWriter`s to record response summaries.
* Add an `ErrorCode` type and application error codes. These are not currently logged or forwarded to the client, though I think it would be nice to do both soon.
* Logger calls that may incur overhead (such as function calls) are now wrapped in `Logger.ShouldLog()` checks. This check is omitted if the log fields contain simple string values, since `Logger.Log()` calls `Logger.ShouldLog()` internally.
* Remove the last few `log.Printf()` and `debug.PrintStack()` calls.
* `Logger.Log()` and all `SimpleLogger` convenience methods now return errors, and use syslog severity levels for compatibility with the Heka message format.