add documentation

This commit is contained in:
2021-05-09 17:25:23 -04:00
parent 1ee89cad34
commit 573de70682
5 changed files with 45 additions and 17 deletions

View File

@@ -6,6 +6,7 @@ import (
"os"
)
// Log provices a simple leveled logger
type Log struct {
quiet bool
debug bool
@@ -13,6 +14,7 @@ type Log struct {
stdOut io.Writer
}
// NewLogger returns a new logger (duh) with the given levels and output writers
func NewLogger(quiet, debug bool, stdOut, errOut io.Writer) *Log {
if stdOut == nil {
stdOut = os.Stdout
@@ -28,32 +30,38 @@ func NewLogger(quiet, debug bool, stdOut, errOut io.Writer) *Log {
}
}
// Error logs at the error level
func (l *Log) Error(s ...interface{}) {
fmt.Fprint(l.errOut, s...)
}
// Errorf uses fmt.Fprint formatting
func (l *Log) Errorf(f string, s ...interface{}) {
fmt.Fprint(l.errOut, s...)
fmt.Fprintf(l.errOut, f, s...)
}
// Log only logs if quiet is false
func (l *Log) Log(s ...interface{}) {
if !l.quiet {
fmt.Fprint(l.stdOut, s...)
}
}
// Logf uses fmt.Fprint fprmatting
func (l *Log) Logf(f string, s ...interface{}) {
if !l.quiet {
fmt.Fprintf(l.stdOut, f, s...)
}
}
// Debug logs debug-level logs if debug is true
func (l *Log) Debug(s ...interface{}) {
if l.debug {
fmt.Fprint(l.errOut, s...)
}
}
// Debugf uses fmt.Fprint fprmatting
func (l *Log) Debugf(f string, s ...interface{}) {
if l.debug {
fmt.Fprintf(l.errOut, f, s...)