/
log.go
96 lines (77 loc) · 2.33 KB
/
log.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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
package logger
import (
"context"
"github.com/tal-tech/loggerX/builders"
"github.com/tal-tech/loggerX/logutils"
"github.com/tal-tech/loggerX/plugin"
)
//global builer
var builder MessageBuilder = new(builders.DefaultBuilder)
//builer interface
type MessageBuilder interface {
//log build
LoggerX(ctx context.Context, lvl string, tag string, args interface{}, v ...interface{})
//log format
Build(ctx context.Context, args interface{}, v ...interface{}) (position, message string)
}
//builder select
func SetBuilder(b MessageBuilder) {
builder = b
}
//INFO level
func I(tag string, args interface{}, v ...interface{}) {
builder.LoggerX(nil, "INFO", tag, args, v...)
}
//INFO with context
func Ix(ctx context.Context, tag string, args interface{}, v ...interface{}) {
builder.LoggerX(ctx, "INFO", tag, args, v...)
}
//TRACE level
func T(tag string, args interface{}, v ...interface{}) {
builder.LoggerX(nil, "TRACE", tag, args, v...)
}
//TRACE level with context
func Tx(ctx context.Context, tag string, args interface{}, v ...interface{}) {
builder.LoggerX(ctx, "TRACE", tag, args, v...)
}
//DEBUG level
func D(tag string, args interface{}, v ...interface{}) {
builder.LoggerX(nil, "DEBUG", tag, args, v...)
}
//DEBUG level with context
func Dx(ctx context.Context, tag string, args interface{}, v ...interface{}) {
builder.LoggerX(ctx, "DEBUG", tag, args, v...)
}
//WARNING level
func W(tag string, args interface{}, v ...interface{}) {
builder.LoggerX(nil, "WARNING", tag, args, v...)
}
//WARNING level with context
func Wx(ctx context.Context, tag string, args interface{}, v ...interface{}) {
builder.LoggerX(ctx, "WARNING", tag, args, v...)
}
//ERROR level
func E(tag string, args interface{}, v ...interface{}) {
builder.LoggerX(nil, "ERROR", tag, args, v...)
}
//ERROR level with context
func Ex(ctx context.Context, tag string, args interface{}, v ...interface{}) {
builder.LoggerX(ctx, "ERROR", tag, args, v...)
}
//CRITICAL level
func C(tag string, args interface{}, v ...interface{}) {
builder.LoggerX(nil, "CRITICAL", tag, args, v...)
}
//FATAL level
func F(tag string, args interface{}, v ...interface{}) {
builder.LoggerX(nil, "FATAL", tag, args, v...)
}
//id generate
func Id() int64 {
return logutils.GenLoggerId()
}
//perf monitor
func RegisterPerfPlugin(perfFunc plugin.PerfPlugin) {
plugin.PerfPluginer = &perfFunc
return
}