-
Notifications
You must be signed in to change notification settings - Fork 32
/
logging.go
57 lines (48 loc) · 1.46 KB
/
logging.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
package util
import (
"fmt"
"io"
"github.com/mattn/go-colorable"
"github.com/mgutz/ansi"
)
var cyan func(string) string
var red func(string) string
var yellow func(string) string
var redInverse func(string) string
var gray func(string) string
var magenta func(string) string
var writer io.Writer
func init() {
ansi.DisableColors(false)
cyan = ansi.ColorFunc("cyan")
red = ansi.ColorFunc("red+b")
yellow = ansi.ColorFunc("yellow+b")
redInverse = ansi.ColorFunc("white:red")
gray = ansi.ColorFunc("black+h")
magenta = ansi.ColorFunc("magenta+h")
writer = colorable.NewColorableStdout()
}
// Debug writes a debug statement to stdout.
func Debug(group string, format string, any ...interface{}) {
fmt.Fprint(writer, gray(group)+" ")
fmt.Fprintf(writer, gray(format), any...)
}
// Info writes an info statement to stdout.
func Info(group string, format string, any ...interface{}) {
fmt.Fprint(writer, cyan(group)+" ")
fmt.Fprintf(writer, format, any...)
}
// Error writes an error statement to stdout.
func Error(group string, format string, any ...interface{}) {
fmt.Fprintf(writer, red(group)+" ")
fmt.Fprintf(writer, red(format), any...)
}
// Panic writes an error statement to stdout.
func Panic(group string, format string, any ...interface{}) {
fmt.Fprintf(writer, redInverse(group)+" ")
fmt.Fprintf(writer, redInverse(format), any...)
}
// Deprecate writes a deprecation warning.
func Deprecate(message string) {
fmt.Fprintf(writer, yellow("godo")+" "+message)
}