Skip to content

Commit 1a748ec

Browse files
author
Aaron Schlesinger
committed
ref(log.go): move debug, warn and info prefixes into constants
also send the actual info message on stdout
1 parent f29d10c commit 1a748ec

1 file changed

Lines changed: 13 additions & 6 deletions

File tree

log/log.go

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,13 @@ var (
4040
Green = Color(prettyprint.Colors["Green"])
4141
)
4242

43+
const (
44+
DebugPrefix = "[DEBUG]"
45+
ErrorPrefix = "[ERROR]"
46+
WarnPrefix = "[WARN]"
47+
InfoPrefix = "--->"
48+
)
49+
4350
// Logger is the base logging struct from which all logging functionality stems
4451
type Logger struct {
4552
stdout io.Writer
@@ -98,7 +105,7 @@ func CleanExit(format string, v ...interface{}) {
98105

99106
// Err prints an error message. It does not cause an exit.
100107
func (l *Logger) Err(format string, v ...interface{}) {
101-
fmt.Fprint(Stderr, addColor("[ERROR] ", Red))
108+
fmt.Fprint(Stderr, addColor(ErrorPrefix+" ", Red))
102109
fmt.Fprintf(Stderr, appendNewLine(format), v...)
103110
}
104111

@@ -107,10 +114,10 @@ func Err(format string, v ...interface{}) {
107114
DefaultLogger.Err(format, v...)
108115
}
109116

110-
// Info prints a green-tinted message.
117+
// Info prints a green-tinted message
111118
func (l *Logger) Info(format string, v ...interface{}) {
112-
fmt.Fprint(l.stderr, addColor("---> ", Green))
113-
fmt.Fprintf(l.stderr, appendNewLine(format), v...)
119+
fmt.Fprint(l.stderr, addColor(InfoPrefix+" ", Green))
120+
fmt.Fprintf(l.stdout, appendNewLine(format), v...)
114121
}
115122

116123
// Info is a convenience function for DefaultLogger.Info(...)
@@ -121,7 +128,7 @@ func Info(format string, v ...interface{}) {
121128
// Debug prints a cyan-tinted message if IsDebugging is true.
122129
func (l *Logger) Debug(msg string, v ...interface{}) {
123130
if l.debug {
124-
fmt.Fprint(l.stderr, addColor("[DEBUG] ", Cyan))
131+
fmt.Fprint(l.stderr, addColor(DebugPrefix+" ", Cyan))
125132
l.Msg(msg, v...)
126133
}
127134
}
@@ -133,7 +140,7 @@ func Debug(msg string, v ...interface{}) {
133140

134141
// Warn prints a yellow-tinted warning message.
135142
func (l *Logger) Warn(format string, v ...interface{}) {
136-
fmt.Fprint(l.stderr, addColor("[WARN] ", Yellow))
143+
fmt.Fprint(l.stderr, addColor(WarnPrefix+" ", Yellow))
137144
l.Msg(format, v...)
138145
}
139146

0 commit comments

Comments
 (0)