forked from deis/builder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
log.go
63 lines (51 loc) · 1.67 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
// Package log is a convenience wrapper for logging messages of various levels (associated colors to come)
// to the terminal. Much of this code has been shamelessly stolen from https://github.com/helm/helm/blob/master/log/log.go
package log
import (
"fmt"
"io"
"os"
"github.com/labstack/gommon/color"
)
// Stdout is the logging destination for normal messages.
var Stdout io.Writer = os.Stdout
// Stderr is the logging destination for error messages.
var Stderr io.Writer = os.Stderr
// IsDebugging toggles whether or not to enable debug output and behavior.
var IsDebugging = false
// Msg passes through the formatter, but otherwise prints exactly as-is.
//
// No prettification.
func Msg(format string, v ...interface{}) {
fmt.Fprintf(Stdout, appendNewLine(format), v...)
}
// CleanExit prints a message and then exits with 0.
func CleanExit(format string, v ...interface{}) {
Info(format, v...)
os.Exit(0)
}
// Err prints an error message. It does not cause an exit.
func Err(format string, v ...interface{}) {
fmt.Fprint(Stderr, color.Red("[ERROR] "))
fmt.Fprintf(Stderr, appendNewLine(format), v...)
}
// Info prints a green-tinted message.
func Info(format string, v ...interface{}) {
fmt.Fprint(Stdout, "-----> ")
fmt.Fprintf(Stdout, appendNewLine(format), v...)
}
// Debug prints a cyan-tinted message if IsDebugging is true.
func Debug(msg string, v ...interface{}) {
if IsDebugging {
fmt.Fprint(Stderr, color.Cyan("[DEBUG] "))
Msg(msg, v...)
}
}
// Warn prints a yellow-tinted warning message.
func Warn(format string, v ...interface{}) {
fmt.Fprint(Stderr, color.Yellow("[WARN] "))
Msg(format, v...)
}
func appendNewLine(format string) string {
return format + "\n"
}