forked from gkmngrgn/dosh-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
logger.go
52 lines (41 loc) · 1.24 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
package dosh
import (
"errors"
"fmt"
"github.com/logrusorgru/aurora"
)
type verbosity int
const (
VerbosityQUIET verbosity = iota - 1
VerbosityNORMAL
VerbosityDEBUG
)
const appVerbosity = VerbosityNORMAL // TODO: get the verbosity from the settings
func renderMessage(v verbosity, msg string, args ...interface{}) (string, error) {
if appVerbosity == VerbosityQUIET && v > appVerbosity {
return "", errors.New("insufficient verbosity")
}
return fmt.Sprintf(msg, args...), nil
}
type Logger interface {
info(v verbosity, msg string, args ...interface{})
success(v verbosity, msg string, args ...interface{})
error(v verbosity, msg string, args ...interface{})
}
// Log func WHY SHOULD I WRITE COMMENT FOR ALL EXPORTED FUNCS?!
type Log struct{}
func (l Log) error(v verbosity, msg string, args ...interface{}) {
if msg, err := renderMessage(v, msg, args...); err == nil {
fmt.Println(aurora.Red(msg))
}
}
func (l Log) success(v verbosity, msg string, args ...interface{}) {
if msg, err := renderMessage(v, msg, args...); err == nil {
fmt.Println(aurora.Green(msg))
}
}
func (l Log) info(v verbosity, msg string, args ...interface{}) {
if msg, err := renderMessage(v, msg, args...); err == nil {
fmt.Println(aurora.White(msg))
}
}