This repository has been archived by the owner on Dec 31, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
logx.go
132 lines (104 loc) · 2.27 KB
/
logx.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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
package sugar
import (
"github.com/hedzr/log"
"go.uber.org/zap"
"io"
)
type dzl struct {
Logger *zap.SugaredLogger
}
func (s *dzl) AddSkip(skip int) log.Logger {
return s
}
func (s *dzl) Tracef(msg string, args ...interface{}) {
if log.GetTraceMode() {
s.Logger.Debugf(msg, args...)
}
}
func (s *dzl) Debugf(msg string, args ...interface{}) {
if log.GetDebugMode() {
s.Logger.Debugf(msg, args...)
}
}
func (s *dzl) Infof(msg string, args ...interface{}) {
s.Logger.Infof(msg, args...)
}
func (s *dzl) Warnf(msg string, args ...interface{}) {
s.Logger.Warnf(msg, args...)
}
func (s *dzl) Errorf(msg string, args ...interface{}) {
s.Logger.Errorf(msg, args...)
}
func (s *dzl) Fatalf(msg string, args ...interface{}) {
s.Logger.Fatalf(msg, args...)
}
func (s *dzl) Panicf(msg string, args ...interface{}) {
s.Logger.Panicf(msg, args...)
}
func (s *dzl) Printf(msg string, args ...interface{}) {
s.Logger.Infof(msg, args...)
}
//
//
func (s *dzl) Trace(args ...interface{}) {
if log.GetTraceMode() {
// s.Logger.Debugw(msg, fields...)
}
}
func (s *dzl) Debug(args ...interface{}) {
if log.GetDebugMode() {
// s.Logger.Debugw(msg, fields...)
}
}
func (s *dzl) Info(args ...interface{}) {
// s.Logger.Infow(msg, fields...)
}
func (s *dzl) Warn(args ...interface{}) {
// s.Logger.Warnw(msg, fields...)
}
func (s *dzl) Error(args ...interface{}) {
// s.Logger.Errorw(msg, fields...)
}
func (s *dzl) Fatal(args ...interface{}) {
// s.Logger.Fatalw(msg, fields...)
}
func (s *dzl) Print(args ...zap.Field) {
// s.Logger.Infow(msg, fields...)
}
//
//
func (s *dzl) SetLevel(lvl log.Level) {
// panic("implement me")
}
func (s *dzl) GetLevel() log.Level {
// panic("implement me")
return log.DebugLevel
}
func (s *dzl) SetOutput(out io.Writer) {
// s.Logger.Out = out
}
func (s *dzl) GetOutput() (out io.Writer) {
return
}
func (s *dzl) Setup() {
// initLogger("", "")
}
// func (s *dzl) AsFieldLogger() logx.FieldLogger {
// return s
// }
func AsFieldLogger(s log.Logger) FieldLogger {
if l, ok := s.(FieldLogger); ok {
return l
}
return nil
}
type FieldLogger interface {
log.Logger
Trace(args ...zap.Field)
Debug(args ...zap.Field)
Info(args ...zap.Field)
Warn(args ...zap.Field)
Error(args ...zap.Field)
Fatal(args ...zap.Field)
Print(args ...zap.Field)
}