/
global.go
69 lines (55 loc) · 1.57 KB
/
global.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
package console
import (
"os"
"github.com/mattn/go-isatty"
)
// ConsoleInstance is the global instance of console, so we don't have to pass it around everywhere
var ConsoleInstance *Console = &Console{
Color: true,
Level: InfoLevel,
IsMachine: false,
}
// SetLevel sets log level
func SetLevel(level Level) {
ConsoleInstance.Level = level
}
// SetColor sets whether to print colors
func SetColor(color bool) {
ConsoleInstance.Color = color
}
// Debug level message.
func Debug(msg string, v ...interface{}) {
ConsoleInstance.Debug(msg, v...)
}
// Info level message.
func Info(msg string, v ...interface{}) {
ConsoleInstance.Info(msg, v...)
}
// Warn level message.
func Warn(msg string, v ...interface{}) {
ConsoleInstance.Warn(msg, v...)
}
// Error level message.
func Error(msg string, v ...interface{}) {
ConsoleInstance.Error(msg, v...)
}
// Fatal level message.
func Fatal(msg string, v ...interface{}) {
ConsoleInstance.Fatal(msg, v...)
}
// Output a line to stdout. Useful for printing primary output of a command, or the output of a subcommand.
func Output(line string) {
ConsoleInstance.Output(line)
}
// OutputErr a line to stderr. Useful for printing primary output of a command, or the output of a subcommand.
func OutputErr(line string) {
ConsoleInstance.OutputErr(line)
}
// DebugOutput a line to stdout. Like Output, but only when level is DebugLevel.
func DebugOutput(line string) {
ConsoleInstance.DebugOutput(line)
}
// IsTTY checks if a file is a TTY or not. E.g. IsTTY(os.Stdin)
func IsTTY(f *os.File) bool {
return isatty.IsTerminal(f.Fd())
}