-
Notifications
You must be signed in to change notification settings - Fork 1
/
log.go
101 lines (89 loc) · 3.59 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
// Package log is an alternative to log package in standard library.
package log
import (
"fmt"
"os"
)
type Level int
// Decode fills this level from the given input string.
// This makes `Level` implement the `Decoder` interface of `envconfig` library,
// so it can be used in config types seamlessly.
func (l *Level) Decode(val string) error {
if logLevel, ok := logLevelMap[val]; ok {
*l = logLevel
return nil
} else {
return fmt.Errorf("Unknown log level configured: %s", val)
}
}
// Logging levels.
const (
CRITICAL Level = iota
ERROR
WARNING
NOTICE
INFO
DEBUG
)
var (
DefaultLogger Logger = NewLogger(procName)
DefaultLevel Level = INFO
DefaultHandler Handler = NewFileHandler(os.Stderr)
DefaultFormatter Formatter = defaultFormatter{}
)
///////////////////
// //
// DefaultLogger //
// //
///////////////////
// SetLevel changes the level of DefaultLogger and DefaultHandler.
func SetLevel(l Level) {
DefaultLogger.SetLevel(l)
DefaultHandler.SetLevel(l)
}
func Fatal(args ...interface{}) { DefaultLogger.Fatal(args...) }
func Fatalf(format string, args ...interface{}) { DefaultLogger.Fatalf(format, args...) }
func Fatalln(args ...interface{}) { DefaultLogger.Fatalln(args...) }
func Panic(args ...interface{}) { DefaultLogger.Panic(args...) }
func Panicf(format string, args ...interface{}) { DefaultLogger.Panicf(format, args...) }
func Panicln(args ...interface{}) { DefaultLogger.Panicln(args...) }
func Critical(args ...interface{}) { DefaultLogger.Critical(args...) }
func Criticalf(format string, args ...interface{}) { DefaultLogger.Criticalf(format, args...) }
func Criticalln(args ...interface{}) { DefaultLogger.Criticalln(args...) }
func Error(args ...interface{}) { DefaultLogger.Error(args...) }
func Errorf(format string, args ...interface{}) { DefaultLogger.Errorf(format, args...) }
func Errorln(args ...interface{}) { DefaultLogger.Errorln(args...) }
func Warning(args ...interface{}) { DefaultLogger.Warning(args...) }
func Warningf(format string, args ...interface{}) { DefaultLogger.Warningf(format, args...) }
func Warningln(args ...interface{}) { DefaultLogger.Warningln(args...) }
func Notice(args ...interface{}) { DefaultLogger.Notice(args...) }
func Noticef(format string, args ...interface{}) { DefaultLogger.Noticef(format, args...) }
func Noticeln(args ...interface{}) { DefaultLogger.Noticeln(args...) }
func Info(args ...interface{}) { DefaultLogger.Info(args...) }
func Infof(format string, args ...interface{}) { DefaultLogger.Infof(format, args...) }
func Infoln(args ...interface{}) { DefaultLogger.Infoln(args...) }
func Debug(args ...interface{}) { DefaultLogger.Debug(args...) }
func Debugf(format string, args ...interface{}) { DefaultLogger.Debugf(format, args...) }
func Debugln(args ...interface{}) { DefaultLogger.Debugln(args...) }
const (
logLevelCritical = "critical"
logLevelError = "error"
logLevelWarning = "warning"
logLevelNotice = "notice"
logLevelInfo = "info"
logLevelDebug = "debug"
)
var logLevelMap = map[string]Level{
logLevelCritical: CRITICAL,
logLevelError: ERROR,
logLevelWarning: WARNING,
logLevelNotice: NOTICE,
logLevelInfo: INFO,
logLevelDebug: DEBUG,
}
var logLevelNameMap = make(map[Level]string)
func init() {
for name, value := range logLevelMap {
logLevelNameMap[value] = name
}
}