-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.go
52 lines (44 loc) · 1.18 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
package main
import (
"fmt"
"github.com/fatih/color"
"io"
"os"
)
var (
Stdout io.Writer = os.Stdout
Stderr io.Writer = os.Stderr
)
func Printf(format string, a ...interface{}) {
fmt.Fprintf(Stdout, format, a...)
fmt.Fprintln(Stdout)
}
func Debug(format string, a ...interface{}) {
if DEBUG {
fmt.Fprintf(Stdout, color.HiBlackString("[DEBUG]"))
fmt.Fprintf(Stdout, color.HiWhiteString("[%s] ", TimeStamp()))
fmt.Fprintf(Stdout, format, a...)
fmt.Fprintln(Stdout)
}
}
func Info(format string, a ...interface{}) {
fmt.Fprintf(Stdout, color.HiCyanString("[INFO]"))
fmt.Fprintf(Stdout, color.HiWhiteString("[%s] ", TimeStamp()))
fmt.Fprintf(Stdout, format, a...)
fmt.Fprintln(Stdout)
}
func Warn(format string, a ...interface{}) {
fmt.Fprintf(Stderr, color.HiYellowString("[WARN]"))
fmt.Fprintf(Stderr, color.HiWhiteString("[%s] ", TimeStamp()))
fmt.Fprintf(Stderr, format, a...)
fmt.Fprintln(Stderr)
}
func Error(format string, a ...interface{}) {
fmt.Fprintf(Stderr, color.HiRedString("[ERROR]"))
fmt.Fprintf(Stderr, color.HiWhiteString("[%s] ", TimeStamp()))
fmt.Fprintf(Stderr, format, a...)
fmt.Fprintln(Stderr)
}
func TimeStamp() string {
return Now().Format("15:04:05")
}