-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathlogger.go
More file actions
34 lines (28 loc) · 719 Bytes
/
logger.go
File metadata and controls
34 lines (28 loc) · 719 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
package main
import (
"fmt"
"os"
"github.com/fatih/color"
)
func logger(typeLog, Flag, message, reason interface{}, errorRange int) {
flagNoColor := flagNoColor
if flagNoColor {
color.NoColor = true // disables colorized output
}
yellow := color.New(color.FgYellow).SprintFunc()
red := color.New(color.FgRed).SprintFunc()
switch typeLog {
case "success":
fmt.Fprintf(os.Stderr, "%s %s\n", yellow(Flag), message)
case "error":
if reason != "" && reason != nil {
fmt.Fprintf(os.Stderr, "%s %s\n", red("[Error]"), message)
fmt.Fprintf(os.Stderr, "Reason: %s\n", reason)
} else {
fmt.Fprintf(os.Stderr, "%s %s\n", red("[Error]"), message)
}
if errorRange == 1 {
os.Exit(1)
}
}
}