port common labels into tag functions

This commit is contained in:
Mya 2022-12-19 12:15:14 -06:00
parent e819b48287
commit 1c628d975c
No known key found for this signature in database
GPG Key ID: C3ECFA648DAD27FA
2 changed files with 32 additions and 17 deletions

View File

@ -144,10 +144,10 @@ func (c Client) Trace(ctxp *context.Context, tags ...Tag) ActiveTrace {
With(tags...)
if c.level <= LevelTrace {
c.With(String("bookend", "start"), String("fn", name)).
c.With(String("bookend", "start"), level(LevelTrace)).
emit(&pb.Entry{
Kind: pb.Kind_Log,
Scope: "trace",
Scope: name,
})
}
@ -172,12 +172,13 @@ func (a *active) Done() {
a.c = a.c.With(Duration("duration", duration))
if a.c.level <= LevelTrace {
a.c.With(String("bookend", "end"), String("fn", a.name)).emit(
&pb.Entry{
Kind: pb.Kind_Log,
Scope: "trace",
},
)
a.c.With(String("bookend", "end"), level(LevelTrace)).
emit(
&pb.Entry{
Kind: pb.Kind_Log,
Scope: a.name,
},
)
}
// trace
@ -194,11 +195,13 @@ func (c Client) Debug(msg string, tags ...Tag) {
return
}
name, _ := caller(c.callerSkip)
c.With(tags...).
With(String("msg", msg)).
With(message(msg), level(LevelDebug)).
emit(&pb.Entry{
Kind: pb.Kind_Log,
Scope: "debug",
Scope: name,
})
}
@ -208,11 +211,13 @@ func (c Client) Info(msg string, tags ...Tag) {
return
}
name, _ := caller(c.callerSkip)
c.With(tags...).
With(String("msg", msg)).
With(message(msg), level(LevelInfo)).
emit(&pb.Entry{
Kind: pb.Kind_Log,
Scope: "info",
Scope: name,
})
}
@ -222,11 +227,13 @@ func (c Client) Warn(msg string, tags ...Tag) {
return
}
name, _ := caller(c.callerSkip)
c.With(tags...).
With(String("msg", msg)).
With(message(msg), level(LevelWarn)).
emit(&pb.Entry{
Kind: pb.Kind_Log,
Scope: "warn",
Scope: name,
})
}
@ -236,11 +243,13 @@ func (c Client) Error(msg string, tags ...Tag) {
return
}
name, _ := caller(c.callerSkip)
c.With(tags...).
With(String("msg", msg)).
With(message(msg), level(LevelError)).
emit(&pb.Entry{
Kind: pb.Kind_Log,
Scope: "error",
Scope: name,
})
}
@ -263,7 +272,7 @@ func (c Client) emit(entries ...*pb.Entry) {
}
// caller attempts to get method caller information. This information is used for tracing information across an
// applications source code.
// applications source code. Need to look into the performance of this call. Parts of it may be able to be cached.
func caller(skip int) (name string, line int) {
pctr, _, line, ok := runtime.Caller(skip)
if !ok {

View File

@ -25,3 +25,9 @@ func Err(err error) Tag { return Tag{"err", err} }
// Errp returns a Tag whose value is read after submission.
func Errp(err *error) Tag { return Tag{"err", err} }
// level returns a tag that contains the string representation of a level.
func level(level Level) Tag { return Tag{"level", (&level).String()} }
// message returns a tag containing message string to index.
func message(msg string) Tag { return Tag{"msg", msg} }