-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcontrolbox_log.go
More file actions
54 lines (41 loc) · 1.24 KB
/
controlbox_log.go
File metadata and controls
54 lines (41 loc) · 1.24 KB
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
package main
import (
"fmt"
"time"
)
// Logging interface
func (h *controlbox) Trace(args ...interface{}) {
// h.print("TRACE", args...)
}
func (h *controlbox) Tracef(format string, args ...interface{}) {
// h.printFormat("TRACE", format, args...)
}
func (h *controlbox) Debug(args ...interface{}) {
// h.print("DEBUG", args...)
}
func (h *controlbox) Debugf(format string, args ...interface{}) {
// h.printFormat("DEBUG", format, args...)
}
func (h *controlbox) Info(args ...interface{}) {
h.print("INFO ", args...)
}
func (h *controlbox) Infof(format string, args ...interface{}) {
h.printFormat("INFO ", format, args...)
}
func (h *controlbox) Error(args ...interface{}) {
h.print("ERROR", args...)
}
func (h *controlbox) Errorf(format string, args ...interface{}) {
h.printFormat("ERROR", format, args...)
}
func (h *controlbox) currentTimestamp() string {
return time.Now().Format("2006-01-02 15:04:05")
}
func (h *controlbox) print(msgType string, args ...interface{}) {
value := fmt.Sprintln(args...)
fmt.Printf("%s %s %s", h.currentTimestamp(), msgType, value)
}
func (h *controlbox) printFormat(msgType, format string, args ...interface{}) {
value := fmt.Sprintf(format, args...)
fmt.Println(h.currentTimestamp(), msgType, value)
}