forked from git-hooks/git-hooks
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.go
78 lines (62 loc) · 1.47 KB
/
logger.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
72
73
74
75
76
77
78
package main
import (
"fmt"
"github.com/wsxiaoys/terminal/color"
"os"
)
type Logger struct {
errors []interface{}
infos []interface{}
warns []interface{}
}
func (logger *Logger) Error(msgs ...interface{}) {
logger.Errors(1, msgs...)
}
func (logger *Logger) Errors(status int, msgs ...interface{}) {
if isTestEnv() {
logger.errors = append(logger.errors, msgs...)
return
}
msgs = append([]interface{}{"@r"}, msgs...)
color.Print(msgs...)
os.Exit(status)
}
func (logger *Logger) Warn(msgs ...interface{}) {
if isTestEnv() {
logger.warns = append(logger.warns, msgs...)
return
}
msgs = append([]interface{}{"@y"}, msgs...)
color.Print(msgs...)
}
func (logger *Logger) Info(msgs ...interface{}) {
if isTestEnv() {
logger.infos = append(logger.infos, msgs...)
return
}
color.Print(msgs...)
}
func (logger *Logger) Errorln(msgs ...interface{}) {
logger.Errorsln(1, msgs...)
}
func (logger *Logger) Errorsln(status int, msgs ...interface{}) {
logger.Errors(status, append(msgs, "\n")...)
}
func (logger *Logger) Warnln(msgs ...interface{}) {
logger.Warn(append(msgs, "\n")...)
}
func (logger *Logger) Infoln(msgs ...interface{}) {
logger.Info(append(msgs, "\n")...)
}
func (logger *Logger) clear() {
logger.infos = logger.infos[:0]
logger.warns = logger.warns[:0]
logger.errors = logger.errors[:0]
}
func (logger *Logger) flush() {
fmt.Println(logger.infos)
fmt.Println(logger.warns)
fmt.Println(logger.errors)
logger.clear()
}
var logger = new(Logger)