-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.go
71 lines (65 loc) · 1.16 KB
/
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
package main
// This is the escroll logging functions
import (
"os"
"time"
"github.com/wsxiaoys/terminal/color"
)
// Constants for logging
const (
// ISO8601Milli is ISO8601 format in millis
ISO8601Milli = "2006-01-02T15:04:05.000"
Error = "ERROR"
Warn = "WARN"
Info = "INFO"
OK = "OK"
)
func logTimestamp() string {
t := time.Now()
return t.Format(ISO8601Milli)
}
func Log(level, message string) {
var c string
var t string
switch level {
case "Error":
c = "@r"
t = "string"
case "NlnError":
c = "@r"
t = "newline"
level = Error
case "Warn":
c = "@y"
t = "string"
case "NlnWarn":
c = "@y"
t = "newline"
level = Warn
case "OK":
c = "@g"
t = "string"
case "NlnOK":
c = "@g"
t = "newline"
level = OK
case "Info":
c = "@{|}"
t = "string"
case "NlnInfo":
c = "@{|}"
t = "newline"
level = Info
default:
os.Exit(1)
}
if t == "string" {
color.Fprintln(os.Stderr, color.Sprintf("%s%s %s: %s", c, logTimestamp(), level, message))
}
if t == "newline" {
color.Fprintln(os.Stderr, color.Sprintf("\n%s%s %s: %s", c, logTimestamp(), level, message))
}
if level == "Error" {
os.Exit(1)
}
}