-
-
Notifications
You must be signed in to change notification settings - Fork 357
/
log.go
48 lines (39 loc) · 864 Bytes
/
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
package app
import (
"fmt"
"runtime"
)
var (
// DefaultLogger is the logger used to log info and errors.
DefaultLogger func(format string, v ...interface{}) = log
defaultColor string
errorColor string
infoColor string
)
func init() {
switch runtime.GOARCH {
case "wasm", "window":
default:
defaultColor = "\033[00m"
errorColor = "\033[91m"
infoColor = "\033[94m"
}
}
// Log logs according to a format specifier using the default logger.
func Log(format string, v ...interface{}) {
DefaultLogger(format, v...)
}
func log(format string, v ...interface{}) {
errorLevel := false
for _, a := range v {
if _, ok := a.(error); ok {
errorLevel = true
break
}
}
if errorLevel {
fmt.Printf(errorColor+"ERROR ‣ "+defaultColor+format+"\n", v...)
return
}
fmt.Printf(infoColor+"INFO ‣ "+defaultColor+format+"\n", v...)
}