aboutsummaryrefslogtreecommitdiff
path: root/clog/clog.go
blob: d9162b04899b0f5dee8ddf287adfc2cb25a25183 (plain) (blame)
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
package clog

import (
	"fmt"
	"os"
)

func log(str string, keyvals []any) {
	fmt.Fprint(os.Stderr, str + " ")
	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 Error(str string, keyvals ...any) {
	log("ERROR "+str, keyvals)
}

func Debug(str string, keyvals ...any) {
	log("DEBUG "+str, keyvals)
}

func Info(str string, keyvals ...any) {
	log("INFO "+str, keyvals)
}

func Fatal(exit int, str string, keyvals ...any) {
	log("FATAL "+str, keyvals)
	os.Exit(exit)
}