logger: add NewStdLogger that can be used as std *log.Logger

Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
Василий Толстов 2021-08-06 11:52:04 +03:00
parent f386bffd37
commit 1d16983b67

19
logger/stdlogger.go Normal file
View File

@ -0,0 +1,19 @@
package logger
import (
"log"
)
type stdLogger struct {
l Logger
level Level
}
func NewStdLogger(l Logger, level Level) *log.Logger {
return log.New(&stdLogger{l: l, level: level}, "" /* prefix */, 0 /* flags */)
}
func (sl *stdLogger) Write(p []byte) (int, error) {
sl.l.Log(sl.l.Options().Context, sl.level, string(p))
return len(p), nil
}