forked from rnorth/gh-combine-prs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlog.go
94 lines (80 loc) · 2.06 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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
package main
import (
"fmt"
"io"
"github.com/fatih/color"
)
// Logger is an interface for logging
type Logger interface {
Debugf(format string, v ...interface{})
Errorf(format string, v ...interface{})
Infof(format string, v ...interface{})
Successf(format string, v ...interface{})
Warnf(format string, v ...interface{})
Fprintf(w io.Writer, format string, v ...interface{}) (int, error)
Fprintln(w io.Writer, v ...interface{}) (int, error)
Printf(format string, v ...interface{})
Println(v ...interface{})
}
type logger struct {
Verbose bool
}
func newLogger(verbose bool) Logger {
return logger{
Verbose: verbose,
}
}
// Debugf prints a formatted debug message
func (l logger) Debugf(format string, v ...interface{}) {
if !l.Verbose {
return
}
color.White(format, v...)
}
// Errorf prints a formatted error, prepending ">> Error: " to the message
func (l logger) Errorf(format string, v ...interface{}) {
color.Red(">> Error: "+format, v...)
}
// Infof prints a formatted info message
func (l logger) Infof(format string, v ...interface{}) {
color.Blue(format, v...)
}
// Successf prints a formatted success message
func (l logger) Successf(format string, v ...interface{}) {
color.Green(format, v...)
}
// Warnf prints a formatted warn message, prepending ">> Warn: " to the message
func (l logger) Warnf(format string, v ...interface{}) {
if !l.Verbose {
return
}
color.Yellow(">> Warn: "+format, v...)
}
// Fprintf prints a formatted string to a writer
func (l logger) Fprintf(w io.Writer, format string, v ...interface{}) (int, error) {
if !l.Verbose {
return 0, nil
}
return fmt.Fprintf(w, format, v...)
}
// Fprintln prints a string to a writer
func (l logger) Fprintln(w io.Writer, v ...interface{}) (int, error) {
if !l.Verbose {
return 0, nil
}
return fmt.Fprintln(w, v...)
}
// Printf prints a formatted string
func (l logger) Printf(format string, v ...interface{}) {
if !l.Verbose {
return
}
fmt.Printf(format, v...)
}
// Println prints a string
func (l logger) Println(v ...interface{}) {
if !l.Verbose {
return
}
fmt.Println(v...)
}