1
0
Fork 0
gobelt/log
Gregory Eremin 5bf8bb3a36 Introduce log levels 2018-07-27 20:24:57 +02:00
..
README.md Move readme parts to their corresponding packages 2018-07-03 20:33:55 +02:00
context.go Add context to logs, update readme 2018-06-24 02:57:14 +02:00
log.go Introduce log levels 2018-07-27 20:24:57 +02:00

README.md

Log

Package log wraps logrus with a set of convenient short functions. It can also add values to context for future logging.

import "github.com/localhots/gobelt/log"
ctx := context.Background()
ctx = log.ContextWithFields(ctx, log.F{"email": params["email"]})

user, err := signup(ctx, params)
if err != nil {
    log.Errorf(ctx, "Signup failed: %v", err)
    // [ERRO] Signup failed: db: duplicate entry    email=bob@example.com
    return
}

log.Info(ctx, "New user signed up", log.F{
    "id":   user.ID,
    "name": user.Name,
})
// [INFO] New user signed up    email=bob@example.com  id=14  name="Bob Fierce"