Infow/Debugw/Errorw are also supported.
So are the *f variations. Because I'm trying to be nice.
Warn is not included. Because I'm not that nice.
clog.Ctx(ctx).Info("information")
clog.Ctx(ctx).Label(clog.ExampleDebugLabel).Debug("debugging")
clog.Ctx(ctx).Err(err).Error("badness")
Labeling is intended to make categorical lookup of logs much easier.
Many times we build unintentional colloquialisms into our log vocabulary and try to filter on those when looking for info. Ex: logs that say "recoverable error" are "the important error logs". No, none of that.
If you have a set of loging that you always want to include or exclude, put a label on it. "How was this run configured?" -> filter clabel like /clabel_configuration/ "What caused the process to fail?" -> filter clabel like /clabel_error_origin/
clog.CtxErr(ctx, err).
Label(clog.LStartOfRun, clog.LFailureSource).
Info("couldn't start up process")
clog.Ctx(ctx).
Comment(`I could just add this in code... but now we can pull double duty!
whatever I say here is readable to anyone who is looking at the logs (which is good
if I'm trying to tell them what they need to know about due to this log occurring);
it's also a regular comment, as if in code, so the code is now also commented!`).
Info("information")
ctx := clues.Add(ctx, "foo", "bar")
err := clues.New("a bad happened").With("fnords", "smarf")
clog.CtxErr(ctx, err).
With("beaux", "regarde").
Debug("all the info!")
// this produces a log containing:
// {
// "msg": "all the info!",
// "foo": "bar",
// "fnords": "smarf",
// "beaux": "regarde",
// }
set := clog.Settings{
Format: clog.FormatForHumans,
Level: clog.LevelInfo,
}
ctx := clog.Init(ctx, set)
You're using labels to categorize your logs, right? Right? Well then you've already built out your debug logging levels! Want to only include a certain set of your very noisy debug logs? Just specify which label you want included in the debug level.
set := clog.Settings{
Format: clog.LFHuman,
Level: clog.LLDebug,
OnlyLogDebugIfContainsLabel: []string{clog.APICall},
}
ctx := clog.Init(ctx, set)