Finalizing for 1.2.0

This commit is contained in:
2022-01-16 06:55:29 -05:00
parent 39e0a1fd43
commit d98363c0d7
22 changed files with 1106 additions and 110 deletions

View File

@@ -2,6 +2,7 @@ package logging
import (
"fmt"
`io`
`log`
`os`
`strings`
@@ -13,14 +14,34 @@ import (
*/
func (l *StdLogger) Setup() (err error) {
var multi io.Writer
// This uses a shared handle across the import. We don't want that.
// l.Logger = log.Default()
if l.Prefix != "" {
l.Prefix = strings.TrimRight(l.Prefix, " ") + " "
// l.Logger.SetPrefix(l.Prefix)
}
// (stdlib).log.std is returned by log.Default(), which uses os.Stderr.
l.Logger = log.New(os.Stderr, l.Prefix, l.LogFlags)
// (stdlib).log.std is returned by log.Default(), which uses os.Stderr but we have flags for that.
// https://stackoverflow.com/a/36719588/733214
switch {
case l.EnableStdErr && l.EnableStdOut:
multi = io.MultiWriter(os.Stdout, os.Stderr)
case l.EnableStdErr:
multi = os.Stderr
case l.EnableStdOut:
multi = os.Stdout
default:
multi = nil
}
if multi != nil {
l.Logger = log.New(multi, l.Prefix, l.LogFlags)
} else {
// This honestly should throw an error.
l.Logger = &log.Logger{}
l.Logger.SetPrefix(l.Prefix)
l.Logger.SetFlags(l.LogFlags)
}
return
}