-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathlogger.go
More file actions
52 lines (45 loc) · 832 Bytes
/
logger.go
File metadata and controls
52 lines (45 loc) · 832 Bytes
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 main
import (
"fmt"
"os"
"runtime"
"github.com/ttacon/chalk"
)
type Logger struct {
DebugLevel bool
Quiet bool
}
func (l Logger) Debug(a ...interface{}) {
if l.DebugLevel {
//windows < 10 doesn't supports ANSI
if runtime.GOOS == "windows" {
fmt.Println(a)
} else {
fmt.Println(chalk.Cyan, a, chalk.Reset)
}
}
}
func (l Logger) Info(a ...interface{}) {
if !l.Quiet {
if runtime.GOOS == "windows" {
fmt.Println(a)
} else {
fmt.Println(chalk.Green, a, chalk.Reset)
}
}
}
func (l Logger) Warn(a ...interface{}) {
if runtime.GOOS == "windows" {
fmt.Println(a)
} else {
fmt.Println(chalk.Yellow, a, chalk.Reset)
}
}
func (l Logger) Fatal(a ...interface{}) {
if runtime.GOOS == "windows" {
fmt.Println(a)
} else {
fmt.Println(chalk.Red, a, chalk.Reset)
}
os.Exit(1)
}