-
Notifications
You must be signed in to change notification settings - Fork 1
/
log.go
113 lines (92 loc) · 2.47 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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
package log
import (
"os"
"io"
"github.com/sirupsen/logrus"
)
var stdoutLogger = logrus.New()
var stderrLogger = logrus.New()
func init() {
stdoutLogger.Out = os.Stdout
stderrLogger.Out = os.Stderr
}
func SetOutput(out io.Writer) {
stdoutLogger.Out = out
stderrLogger.Out = out
}
// Info is wrapper for logrus.Info to print to stdout
func Info(args ...interface{}) {
stdoutLogger.Info(args...)
}
// Debug is wrapper for logrus.Debug to print to stdout
func Debug(args ...interface{}) {
stdoutLogger.Debug(args...)
}
// Error is wrapper for logrus.Error to print to stderr
func Error(args ...interface{}) {
stderrLogger.Error(args...)
}
// Fatal is wrapper for logrus.Fatal to print to stderr
func Fatal(args ...interface{}) {
stderrLogger.Fatal(args...)
}
// Warn is wrapper for logrus.Warn to print to stderr
func Warn(args ...interface{}) {
stderrLogger.Warn(args...)
}
// Infof is wrapper for logrus.Infof to print to stdout
func Infof(format string, args ...interface{}) {
stdoutLogger.Infof(format, args...)
}
// Debugf is wrapper for logrus.Debugf to print to stdout
func Debugf(format string, args ...interface{}) {
stdoutLogger.Debugf(format, args...)
}
// Errorf is wrapper for logrus.Errorf to print to stderr
func Errorf(format string, args ...interface{}) {
stderrLogger.Errorf(format, args...)
}
// Fatalf is wrapper for logrus.Fatalf to print to stderr
func Fatalf(format string, args ...interface{}) {
stderrLogger.Fatalf(format, args...)
}
// Warnf is wrapper for logrus.Warnf to print to stderr
func Warnf(format string, args ...interface{}) {
stderrLogger.Warnf(format, args...)
}
// ParseLevel takes a string level and returns the Logrus log level constant.
func ParseLevel(lvl string) (logrus.Level, error) {
return logrus.ParseLevel(lvl)
}
// SetLevelString takes in the log level in string format
// some of valid values: error, info, debug ...
func SetLevelString(lvlStr string) error {
level, err := ParseLevel(lvlStr)
if err != nil {
return err
}
SetLevel(level)
return nil
}
// SetLevel sets the log level
func SetLevel(lvl logrus.Level) {
stdoutLogger.Level = lvl
stderrLogger.Level = lvl
}
// GetLevel gets the current log level
func GetLevel() logrus.Level {
return stdoutLogger.Level
}
// GetLevelString gets the current log level
func GetLevelString() string {
var level string
switch stdoutLogger.Level {
case logrus.DebugLevel:
level = "debug"
case logrus.InfoLevel:
level = "info"
case logrus.ErrorLevel:
level = "error"
}
return level
}