-
Notifications
You must be signed in to change notification settings - Fork 2
/
log.go
51 lines (43 loc) · 1.11 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
package udig
import (
"fmt"
"os"
)
// Logging levels: the smaller value the more verbose the output will be.
const (
LogLevelDebug = 0
LogLevelInfo = 10
LogLevelErr = 100
LogLevelNone = 1000
)
const (
errColor = "\033[1;91m"
infoColor = "\033[1;92m"
debugColor = ""
noColor = "\033[0m"
)
// LogLevel contains the actual log level setting.
var LogLevel = LogLevelDebug
// LogPanic formats and prints a given log on STDERR and panics.
func LogPanic(format string, a ...interface{}) {
LogErr(format, a)
panic(nil)
}
// LogErr formats and prints a given log on STDERR.
func LogErr(format string, a ...interface{}) {
if LogLevel <= LogLevelErr {
fmt.Fprintf(os.Stderr, errColor+"[!] "+format+"\n"+noColor, a...)
}
}
// LogInfo formats and prints a given log on STDOUT.
func LogInfo(format string, a ...interface{}) {
if LogLevel <= LogLevelInfo {
fmt.Printf(infoColor+"[+] "+format+"\n"+noColor, a...)
}
}
// LogDebug formats and prints a given log on STDOUT.
func LogDebug(format string, a ...interface{}) {
if LogLevel <= LogLevelDebug {
fmt.Printf(debugColor+"[~] "+format+"\n"+noColor, a...)
}
}