forked from replicate/cog
/
global.go
84 lines (67 loc) · 1.63 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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
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) {
ConsoleInstance.Debug(msg)
}
// Info level message.
func Info(msg string) {
ConsoleInstance.Info(msg)
}
// Warn level message.
func Warn(msg string) {
ConsoleInstance.Warn(msg)
}
// Error level message.
func Error(msg string) {
ConsoleInstance.Error(msg)
}
// Fatal level message.
func Fatal(msg string) {
ConsoleInstance.Fatal(msg)
}
// Debug level message.
func Debugf(msg string, v ...interface{}) {
ConsoleInstance.Debugf(msg, v...)
}
// Info level message.
func Infof(msg string, v ...interface{}) {
ConsoleInstance.Infof(msg, v...)
}
// Warn level message.
func Warnf(msg string, v ...interface{}) {
ConsoleInstance.Warnf(msg, v...)
}
// Error level message.
func Errorf(msg string, v ...interface{}) {
ConsoleInstance.Errorf(msg, v...)
}
// Fatal level message.
func Fatalf(msg string, v ...interface{}) {
ConsoleInstance.Fatalf(msg, v...)
}
// Output a line to stdout. Useful for printing primary output of a command, or the output of a subcommand.
func Output(s string) {
ConsoleInstance.Output(s)
}
// 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())
}