-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlog.go
More file actions
38 lines (31 loc) · 656 Bytes
/
log.go
File metadata and controls
38 lines (31 loc) · 656 Bytes
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 main
import (
"fmt"
"os"
"strings"
"time"
)
var logPrefix = "[main]"
var quiet = false
func SetLog(pre1, pre2 string, q bool) {
quiet = q
if pre1 != "" {
logPrefix = pre1 + " " + pre2
} else {
logPrefix = pre2
}
}
func Log(format string, args ...interface{}) {
if quiet && !strings.Contains(format, "READY") {
return
}
ts := time.Now().Format("15:04:05")
msg := fmt.Sprintf(format, args...)
fmt.Printf("%s %s %s", ts, logPrefix, msg)
}
func Err(format string, args ...interface{}) {
ts := time.Now().Format("15:04:05")
msg := fmt.Sprintf(format, args...)
fmt.Printf("%s %s ERROR: %s", ts, logPrefix, msg)
os.Exit(1)
}