taskcafe/internal/logger/logger.go

22 lines
554 B
Go
Raw Permalink Normal View History

package logger
2020-04-10 04:40:22 +02:00
import (
"context"
2020-04-10 04:40:22 +02:00
"github.com/google/uuid"
"github.com/jordanknott/taskcafe/internal/utils"
log "github.com/sirupsen/logrus"
2020-04-10 04:40:22 +02:00
)
// New returns a log entry with the reqID and userID fields populated if they exist
func New(ctx context.Context) *log.Entry {
entry := log.NewEntry(log.StandardLogger())
if reqID, ok := ctx.Value(utils.ReqIDKey).(uuid.UUID); ok {
entry = entry.WithField("reqID", reqID)
2020-04-10 04:40:22 +02:00
}
if userID, ok := ctx.Value(utils.UserIDKey).(uuid.UUID); ok {
entry = entry.WithField("userID", userID)
2020-04-10 04:40:22 +02:00
}
return entry
}