forked from xjasonlyu/tun2socks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.go
64 lines (51 loc) · 1.26 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
package log
import (
"io"
"os"
"github.com/sirupsen/logrus"
"go.uber.org/atomic"
)
// _defaultLevel is package default logging level.
var _defaultLevel = atomic.NewUint32(uint32(InfoLevel))
func init() {
logrus.SetOutput(os.Stdout)
logrus.SetLevel(logrus.DebugLevel)
}
func SetOutput(out io.Writer) {
logrus.SetOutput(out)
}
func SetLevel(level Level) {
_defaultLevel.Store(uint32(level))
}
func Debugf(format string, args ...any) {
logf(DebugLevel, format, args...)
}
func Infof(format string, args ...any) {
logf(InfoLevel, format, args...)
}
func Warnf(format string, args ...any) {
logf(WarnLevel, format, args...)
}
func Errorf(format string, args ...any) {
logf(ErrorLevel, format, args...)
}
func Fatalf(format string, args ...any) {
//logrus.Fatalf(format, args...)
logf(ErrorLevel, format, args...)
}
func logf(level Level, format string, args ...any) {
event := newEvent(level, format, args...)
if uint32(event.Level) > _defaultLevel.Load() {
return
}
switch level {
case DebugLevel:
logrus.WithTime(event.Time).Debugln(event.Message)
case InfoLevel:
logrus.WithTime(event.Time).Infoln(event.Message)
case WarnLevel:
logrus.WithTime(event.Time).Warnln(event.Message)
case ErrorLevel:
logrus.WithTime(event.Time).Errorln(event.Message)
}
}