mozilla-services / pushgo

🚨🚨🚨OBSOLETE AND UNMAINTAINED🚨🚨🚨 See Autopush for the current server.
https://github.com/mozilla-services/autopush
Mozilla Public License 2.0
24 stars 10 forks source link

Child logger support #191

Open ghost opened 9 years ago

ghost commented 9 years ago

Bunyan's child loggers are handy for prepopulating context-specific log fields. We could use a similar pattern to tag each request—create a child logger with the request ID, then pass that logger to downstream functions.

For example:

func (h *EndpointHandler) UpdateHandler(resp http.ResponseWriter, req *http.Request) {
    log := h.logger.Child(LogFields{"rid": req.Header.Get(HeaderID)})
    // ...
    if err := updateStore(uaid, chid, version, log); err != nil {
        log.Warn("handlers_endpoint",
            "This log message will be tagged with the request ID...",
            LogFields{"error": err.Error()})
    }
}

func updateStore(uaid, chid string, version int64, data string, log *SimpleLogger) error {
    log.Info("storage", "...And so will this", nil)
    return nil
}