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
|
// Package clog provides basic logging utilities.
package clog
import (
"fmt"
"os"
)
func logs(str string, keyvals []any) {
fmt.Fprint(os.Stderr, str)
if len(keyvals) != 0 {
fmt.Fprint(os.Stderr, " ")
for i, j := range keyvals {
if i&1 == 0 {
fmt.Fprintf(os.Stderr, "%v=", j)
} else if i == len(keyvals)-1 {
fmt.Fprintf(os.Stderr, "%#v", j)
} else {
fmt.Fprintf(os.Stderr, "%#v ", j)
}
}
}
fmt.Fprintln(os.Stderr)
}
func Errors(str string, keyvals ...any) {
logs("\x1b[1;91mERROR: "+str, keyvals)
}
func Warns(str string, keyvals ...any) {
logs("\x1b[1;93mWARNING: "+str, keyvals)
}
func Debugs(str string, keyvals ...any) {
logs("\x1b[90mDEBUG: "+str, keyvals)
}
func Infos(str string, keyvals ...any) {
logs("\x1b[0mINFO: "+str, keyvals)
}
func Fatals(exit int, str string, keyvals ...any) {
logs("\x1b[1;35mFATAL: "+str, keyvals)
os.Exit(exit)
}
func log(str string) {
fmt.Fprintln(os.Stderr, str)
}
func Error(str string) {
log("\x1b[1;91mERROR: "+str)
}
func Warn(str string, keyvals ...any) {
log("\x1b[1;93mWARNING: "+str)
}
func Debug(str string, keyvals ...any) {
log("\x1b[90mDEBUG: "+str)
}
func Info(str string, keyvals ...any) {
log("\x1b[0mINFO: "+str)
}
func Fatal(exit int, str string, keyvals ...any) {
log("\x1b[1;35mFATAL: "+str)
os.Exit(exit)
}
|