mirror of
https://github.com/livekit/livekit.git
synced 2026-03-30 19:55:41 +00:00
* Separate from ion-sfu changes: 1. extract pkg/buffer, twcc, sfu, relay, stats, logger 2. to solve cycle import, move ion-sfu/pkg/logger to pkg/sfu/logger 3. replace pion/ion-sfu => ./ reason: will change import pion/ion-sfu/pkg/* to livekit-server/pkg/* after this pr merged. Just not change any code in this pr, because it will confused with the separate code from ion-sfu in review. * Move code from ion-sfu to pkg/sfu * fix build error for resovle conflict Co-authored-by: cnderrauber <zengjie9004@gmail.com>
58 lines
1.3 KiB
Go
58 lines
1.3 KiB
Go
package serverlogger
|
|
|
|
import (
|
|
"github.com/go-logr/logr"
|
|
"github.com/go-logr/zapr"
|
|
"github.com/livekit/livekit-server/pkg/sfu"
|
|
"github.com/livekit/livekit-server/pkg/sfu/buffer"
|
|
"github.com/livekit/protocol/logger"
|
|
"github.com/pion/logging"
|
|
"go.uber.org/zap"
|
|
"go.uber.org/zap/zapcore"
|
|
)
|
|
|
|
var (
|
|
// pion/webrtc, pion/turn
|
|
defaultFactory logging.LoggerFactory
|
|
)
|
|
|
|
func LoggerFactory() logging.LoggerFactory {
|
|
if defaultFactory == nil {
|
|
defaultFactory = logging.NewDefaultLoggerFactory()
|
|
}
|
|
return defaultFactory
|
|
}
|
|
|
|
func SetLoggerFactory(lf logging.LoggerFactory) {
|
|
defaultFactory = lf
|
|
}
|
|
|
|
// Note: only pass in logr.Logger with default depth
|
|
func SetLogger(l logr.Logger) {
|
|
logger.SetLogger(l, "livekit")
|
|
sfu.Logger = l.WithName("sfu")
|
|
buffer.Logger = sfu.Logger
|
|
}
|
|
|
|
func InitProduction(logLevel string) {
|
|
initLogger(zap.NewProductionConfig(), logLevel)
|
|
}
|
|
|
|
func InitDevelopment(logLevel string) {
|
|
initLogger(zap.NewDevelopmentConfig(), logLevel)
|
|
}
|
|
|
|
// valid levels: debug, info, warn, error, fatal, panic
|
|
func initLogger(config zap.Config, level string) {
|
|
if level != "" {
|
|
lvl := zapcore.Level(0)
|
|
if err := lvl.UnmarshalText([]byte(level)); err == nil {
|
|
config.Level = zap.NewAtomicLevelAt(lvl)
|
|
}
|
|
}
|
|
|
|
l, _ := config.Build()
|
|
zapLogger := zapr.NewLogger(l)
|
|
SetLogger(zapLogger)
|
|
}
|