-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Split logging into two verbosity levels
- Loading branch information
Showing
4 changed files
with
46 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package main | ||
|
||
import ( | ||
"fmt" | ||
"io" | ||
"os" | ||
) | ||
|
||
type Logger struct { | ||
writer io.Writer | ||
verbosity int | ||
} | ||
|
||
func LoggerWithVerbosity(verbosity int) *Logger { | ||
if verbosity > 0 { | ||
return &Logger{os.Stderr, verbosity} | ||
} | ||
return nil | ||
} | ||
|
||
func (l *Logger) RequireVerbosity(verbosity int) *Logger { | ||
if l != nil && l.verbosity >= verbosity { | ||
return l | ||
} | ||
return nil | ||
} | ||
|
||
func (l *Logger) Printf(format string, a ...interface{}) { | ||
if l == nil { | ||
return | ||
} | ||
fmt.Fprintf(l.writer, format, a...) | ||
l.writer.Write([]byte("\n")) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters