[chore] simplify logging to remove "safetywriter" given os.File has concurrency protection (#1083)

Signed-off-by: kim <grufwub@gmail.com>

Signed-off-by: kim <grufwub@gmail.com>
This commit is contained in:
kim 2022-11-20 16:40:15 +00:00 committed by GitHub
commit 4a9538593c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 4 additions and 46 deletions

View file

@ -20,7 +20,6 @@ package log
import (
"fmt"
"io"
"log/syslog"
"os"
"strings"
@ -39,10 +38,6 @@ var (
// lvlstrs is the lookup table of log levels to strings.
lvlstrs = level.Default()
// Preprepared stdout/stderr log writers.
stdout = &safewriter{w: os.Stdout}
stderr = &safewriter{w: os.Stderr}
// Syslog output, only set if enabled.
sysout *syslog.Writer
@ -187,12 +182,12 @@ func printf(depth int, fields []kv.Field, s string, a ...interface{}) {
}
// Write to log and release
_, _ = stdout.Write(buf.B)
_, _ = os.Stdout.Write(buf.B)
putBuf(buf)
}
func logf(depth int, lvl level.LEVEL, fields []kv.Field, s string, a ...interface{}) {
var out io.Writer
var out *os.File
// Check if enabled.
if lvl > Level() {
@ -202,9 +197,9 @@ func logf(depth int, lvl level.LEVEL, fields []kv.Field, s string, a ...interfac
// Split errors to stderr,
// all else goes to stdout.
if lvl <= level.ERROR {
out = stderr
out = os.Stderr
} else {
out = stdout
out = os.Stdout
}
// Acquire buffer