forked from git-hooks/git-hooks
/
logger.go
55 lines (51 loc) · 1.11 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
package main
import (
"github.com/wsxiaoys/terminal/color"
"os"
)
var logger = struct {
Error func(...interface{})
Errors func(int, ...interface{})
Warn func(...interface{})
Info func(...interface{})
Errorln func(...interface{})
Errorsln func(int, ...interface{})
Warnln func(...interface{})
Infoln func(...interface{})
}{
Error: Error,
Errors: Errors,
Warn: Warn,
Info: Info,
Errorln: Errorln,
Errorsln: Errorsln,
Warnln: Warnln,
Infoln: Infoln,
}
func Error(msgs ...interface{}) {
Errors(1, msgs...)
}
func Errors(status int, msgs ...interface{}) {
msgs = append([]interface{}{"@r"}, msgs...)
color.Print(msgs...)
os.Exit(status)
}
func Warn(msgs ...interface{}) {
msgs = append([]interface{}{"@y"}, msgs...)
color.Print(msgs...)
}
func Info(msgs ...interface{}) {
color.Print(msgs...)
}
func Errorln(msgs ...interface{}) {
Errorsln(1, msgs...)
}
func Errorsln(status int, msgs ...interface{}) {
Errors(status, append(msgs, "\n")...)
}
func Warnln(msgs ...interface{}) {
Warn(append(msgs, "\n")...)
}
func Infoln(msgs ...interface{}) {
Info(append(msgs, "\n")...)
}