Ejemplo n.º 1
0
func logStartOfRequest(ctx context.Context, r *http.Request) {
	fields := logrus.Fields{
		"path":   r.URL.String(),
		"method": r.Method,
	}

	log.WithFields(ctx, fields).Info("Starting request")
}
Ejemplo n.º 2
0
func logEndOfRequest(ctx context.Context, duration time.Duration, mw mutil.WriterProxy) {
	fields := logrus.Fields{
		"status":   mw.Status(),
		"bytes":    mw.BytesWritten(),
		"duration": duration,
	}

	log.WithFields(ctx, fields).Info("Finished request")
}
Ejemplo n.º 3
0
// initLogglyLog attaches a loggly hook to our logging system.
func initLogglyLog(app *App) {

	if app.config.LogglyToken == "" {
		return
	}

	log.WithFields(log.F{
		"token":       app.config.LogglyToken,
		"loggly_host": app.config.LogglyHost,
	}).Info("Initializing loggly hook")

	hook := log.NewLogglyHook(app.config.LogglyToken)
	log.DefaultLogger.Logger.Hooks.Add(hook)

	go func() {
		<-app.ctx.Done()
		hook.Flush()
	}()
}