port common labels into tag functions
This commit is contained in:
parent
e819b48287
commit
1c628d975c
43
client.go
43
client.go
@ -144,10 +144,10 @@ func (c Client) Trace(ctxp *context.Context, tags ...Tag) ActiveTrace {
|
|||||||
With(tags...)
|
With(tags...)
|
||||||
|
|
||||||
if c.level <= LevelTrace {
|
if c.level <= LevelTrace {
|
||||||
c.With(String("bookend", "start"), String("fn", name)).
|
c.With(String("bookend", "start"), level(LevelTrace)).
|
||||||
emit(&pb.Entry{
|
emit(&pb.Entry{
|
||||||
Kind: pb.Kind_Log,
|
Kind: pb.Kind_Log,
|
||||||
Scope: "trace",
|
Scope: name,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -172,12 +172,13 @@ func (a *active) Done() {
|
|||||||
a.c = a.c.With(Duration("duration", duration))
|
a.c = a.c.With(Duration("duration", duration))
|
||||||
|
|
||||||
if a.c.level <= LevelTrace {
|
if a.c.level <= LevelTrace {
|
||||||
a.c.With(String("bookend", "end"), String("fn", a.name)).emit(
|
a.c.With(String("bookend", "end"), level(LevelTrace)).
|
||||||
&pb.Entry{
|
emit(
|
||||||
Kind: pb.Kind_Log,
|
&pb.Entry{
|
||||||
Scope: "trace",
|
Kind: pb.Kind_Log,
|
||||||
},
|
Scope: a.name,
|
||||||
)
|
},
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
// trace
|
// trace
|
||||||
@ -194,11 +195,13 @@ func (c Client) Debug(msg string, tags ...Tag) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
name, _ := caller(c.callerSkip)
|
||||||
|
|
||||||
c.With(tags...).
|
c.With(tags...).
|
||||||
With(String("msg", msg)).
|
With(message(msg), level(LevelDebug)).
|
||||||
emit(&pb.Entry{
|
emit(&pb.Entry{
|
||||||
Kind: pb.Kind_Log,
|
Kind: pb.Kind_Log,
|
||||||
Scope: "debug",
|
Scope: name,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -208,11 +211,13 @@ func (c Client) Info(msg string, tags ...Tag) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
name, _ := caller(c.callerSkip)
|
||||||
|
|
||||||
c.With(tags...).
|
c.With(tags...).
|
||||||
With(String("msg", msg)).
|
With(message(msg), level(LevelInfo)).
|
||||||
emit(&pb.Entry{
|
emit(&pb.Entry{
|
||||||
Kind: pb.Kind_Log,
|
Kind: pb.Kind_Log,
|
||||||
Scope: "info",
|
Scope: name,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -222,11 +227,13 @@ func (c Client) Warn(msg string, tags ...Tag) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
name, _ := caller(c.callerSkip)
|
||||||
|
|
||||||
c.With(tags...).
|
c.With(tags...).
|
||||||
With(String("msg", msg)).
|
With(message(msg), level(LevelWarn)).
|
||||||
emit(&pb.Entry{
|
emit(&pb.Entry{
|
||||||
Kind: pb.Kind_Log,
|
Kind: pb.Kind_Log,
|
||||||
Scope: "warn",
|
Scope: name,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -236,11 +243,13 @@ func (c Client) Error(msg string, tags ...Tag) {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
name, _ := caller(c.callerSkip)
|
||||||
|
|
||||||
c.With(tags...).
|
c.With(tags...).
|
||||||
With(String("msg", msg)).
|
With(message(msg), level(LevelError)).
|
||||||
emit(&pb.Entry{
|
emit(&pb.Entry{
|
||||||
Kind: pb.Kind_Log,
|
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
|
// 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) {
|
func caller(skip int) (name string, line int) {
|
||||||
pctr, _, line, ok := runtime.Caller(skip)
|
pctr, _, line, ok := runtime.Caller(skip)
|
||||||
if !ok {
|
if !ok {
|
||||||
|
@ -25,3 +25,9 @@ func Err(err error) Tag { return Tag{"err", err} }
|
|||||||
|
|
||||||
// Errp returns a Tag whose value is read after submission.
|
// Errp returns a Tag whose value is read after submission.
|
||||||
func Errp(err *error) Tag { return Tag{"err", err} }
|
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} }
|
||||||
|
Loading…
x
Reference in New Issue
Block a user