-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.go
76 lines (62 loc) · 2.38 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
package lg
import (
"fmt"
"log"
"os"
)
//TODO implement file logging
// Curlevel represents the level of logging below which no log will be printed.
// The maximum available is LeveL_Failure, which will only print critical errors.
// The default is the lowest one, Level_Debug, which will print everything.
// The higher the loglevel, the lower the verbosity
var CurLevel LogLevel
//Do not print date, but print file name and line
var Flags = log.Lshortfile | log.Ltime
var std = log.New(os.Stderr, "", Flags)
var Color bool = true
func _log(level LogLevel, params ...interface{}) {
if level < CurLevel {
return
}
params = append([]interface{}{level.ShortString(Color) + ": "}, params...)
// 3 Is the call depth to print the correct filename
_ = std.Output(3, fmt.Sprint(params...))
}
func _logf(level LogLevel, format string, params ...interface{}) {
if level < CurLevel {
return
}
// 3 Is the call depth to print the correct filename
_ = std.Output(3, fmt.Sprintf(level.ShortString(Color)+": "+format, params...))
}
func SetFlags(flag int) {
std.SetFlags(flag)
}
// Failure behaves as all other logging functions, then panics with the given parameters
func Failure(params ...interface{}) {
_log(Level_Failure, params...)
os.Exit(1)
}
// Failuref behaves as all other logging functions, then panics with the given parameters
func Failuref(format string, params ...interface{}) {
_logf(Level_Failure, format, params...)
os.Exit(1)
}
//The code below is autogenerated
/*
for level in Debug Info Warn Error
do
sed "s/LEVEL/$level/g" <<TMPL
func LEVEL(params ...interface{}) { _log(Level_LEVEL, params...) }
func LEVELf(format string, params ...interface{}) { _logf(Level_LEVEL, format, params...) }
TMPL
done
*/
func Debug(params ...interface{}) { _log(Level_Debug, params...) }
func Debugf(format string, params ...interface{}) { _logf(Level_Debug, format, params...) }
func Info(params ...interface{}) { _log(Level_Info, params...) }
func Infof(format string, params ...interface{}) { _logf(Level_Info, format, params...) }
func Warn(params ...interface{}) { _log(Level_Warn, params...) }
func Warnf(format string, params ...interface{}) { _logf(Level_Warn, format, params...) }
func Error(params ...interface{}) { _log(Level_Error, params...) }
func Errorf(format string, params ...interface{}) { _logf(Level_Error, format, params...) }