Use common logging init functions (#633)
* Use common logging init functions * update protocol commit * fix tests
This commit is contained in:
@@ -22,7 +22,10 @@ func (l *logAdapter) Tracef(format string, args ...interface{}) {
|
||||
}
|
||||
|
||||
func (l *logAdapter) Debug(msg string) {
|
||||
l.Debugf(msg)
|
||||
if l.level > zapcore.DebugLevel {
|
||||
return
|
||||
}
|
||||
l.logger.V(1).Info(msg)
|
||||
}
|
||||
|
||||
func (l *logAdapter) Debugf(format string, args ...interface{}) {
|
||||
@@ -33,7 +36,10 @@ func (l *logAdapter) Debugf(format string, args ...interface{}) {
|
||||
}
|
||||
|
||||
func (l *logAdapter) Info(msg string) {
|
||||
l.Infof(msg)
|
||||
if l.level > zapcore.InfoLevel {
|
||||
return
|
||||
}
|
||||
l.logger.Info(msg)
|
||||
}
|
||||
|
||||
func (l *logAdapter) Infof(format string, args ...interface{}) {
|
||||
@@ -44,7 +50,10 @@ func (l *logAdapter) Infof(format string, args ...interface{}) {
|
||||
}
|
||||
|
||||
func (l *logAdapter) Warn(msg string) {
|
||||
l.Warnf(msg)
|
||||
if l.level > zapcore.WarnLevel {
|
||||
return
|
||||
}
|
||||
l.logger.Info(msg)
|
||||
}
|
||||
|
||||
func (l *logAdapter) Warnf(format string, args ...interface{}) {
|
||||
@@ -55,7 +64,10 @@ func (l *logAdapter) Warnf(format string, args ...interface{}) {
|
||||
}
|
||||
|
||||
func (l *logAdapter) Error(msg string) {
|
||||
l.Errorf(msg)
|
||||
if l.level > zapcore.ErrorLevel {
|
||||
return
|
||||
}
|
||||
l.logger.Error(nil, msg)
|
||||
}
|
||||
|
||||
func (l *logAdapter) Errorf(format string, args ...interface{}) {
|
||||
|
||||
+2
-41
@@ -2,9 +2,7 @@ package serverlogger
|
||||
|
||||
import (
|
||||
"github.com/go-logr/logr"
|
||||
"github.com/go-logr/zapr"
|
||||
"github.com/pion/logging"
|
||||
"go.uber.org/zap"
|
||||
"go.uber.org/zap/zapcore"
|
||||
|
||||
"github.com/livekit/protocol/logger"
|
||||
@@ -43,43 +41,6 @@ func SetLogger(l logr.Logger) {
|
||||
}
|
||||
|
||||
func InitFromConfig(config config.LoggingConfig) {
|
||||
lvl := parseLevel(config.Level)
|
||||
pionLevel = parseLevel(config.PionLevel)
|
||||
if lvl > pionLevel {
|
||||
pionLevel = lvl
|
||||
}
|
||||
zapConfig := zap.Config{
|
||||
Level: zap.NewAtomicLevelAt(lvl),
|
||||
Development: false,
|
||||
Encoding: "console",
|
||||
EncoderConfig: zap.NewDevelopmentEncoderConfig(),
|
||||
OutputPaths: []string{"stderr"},
|
||||
ErrorOutputPaths: []string{"stderr"},
|
||||
}
|
||||
if config.Sample {
|
||||
zapConfig.Sampling = &zap.SamplingConfig{
|
||||
Initial: 100,
|
||||
Thereafter: 100,
|
||||
}
|
||||
}
|
||||
if config.JSON {
|
||||
zapConfig.Encoding = "json"
|
||||
zapConfig.EncoderConfig = zap.NewProductionEncoderConfig()
|
||||
}
|
||||
initLogger(zapConfig)
|
||||
}
|
||||
|
||||
// valid levels: debug, info, warn, error, fatal, panic
|
||||
func initLogger(config zap.Config) {
|
||||
l, _ := config.Build()
|
||||
zapLogger := zapr.NewLogger(l)
|
||||
SetLogger(zapLogger)
|
||||
}
|
||||
|
||||
func parseLevel(level string) zapcore.Level {
|
||||
lvl := zapcore.InfoLevel
|
||||
if level != "" {
|
||||
_ = lvl.UnmarshalText([]byte(level))
|
||||
}
|
||||
return lvl
|
||||
pionLevel = logger.ParseZapLevel(config.PionLevel)
|
||||
logger.InitFromConfig(config.Config, "livekit")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user