-
Notifications
You must be signed in to change notification settings - Fork 0
/
liblogging.go
42 lines (37 loc) · 824 Bytes
/
liblogging.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
package liblogging
import (
"context"
"os"
"github.com/sirupsen/logrus"
"go.elastic.co/apm"
"go.elastic.co/apm/module/apmlogrus"
)
type (
// Logger is ...
Logger struct {
Out *logrus.Logger
Err *logrus.Logger
Field *logrus.Entry
}
)
// New is ...
func New() *Logger {
tx := apm.DefaultTracer.StartTransaction("name", "type")
defer tx.End()
ctx := apm.ContextWithTransaction(context.Background(), tx)
span, ctx := apm.StartSpan(ctx, "name", "type")
defer span.End()
return &Logger{
Out: &logrus.Logger{
Formatter: new(logrus.TextFormatter),
Out: os.Stdout,
Level: logrus.InfoLevel,
},
Err: &logrus.Logger{
Formatter: new(logrus.TextFormatter),
Out: os.Stderr,
Level: logrus.InfoLevel,
},
Field: logrus.WithFields(apmlogrus.TraceContext(ctx)),
}
}