diff --git a/server/internal/webrtc/logger.go b/server/internal/webrtc/logger.go deleted file mode 100644 index 52764867..00000000 --- a/server/internal/webrtc/logger.go +++ /dev/null @@ -1,66 +0,0 @@ -package webrtc - -import ( - "fmt" - "strings" - - "github.com/pion/logging" - "github.com/rs/zerolog" -) - -type nulllog struct{} - -func (l nulllog) Trace(msg string) {} -func (l nulllog) Tracef(format string, args ...interface{}) {} -func (l nulllog) Debug(msg string) {} -func (l nulllog) Debugf(format string, args ...interface{}) {} -func (l nulllog) Info(msg string) {} -func (l nulllog) Infof(format string, args ...interface{}) {} -func (l nulllog) Warn(msg string) {} -func (l nulllog) Warnf(format string, args ...interface{}) {} -func (l nulllog) Error(msg string) {} -func (l nulllog) Errorf(format string, args ...interface{}) {} - -type logger struct { - logger zerolog.Logger - subsystem string -} - -func (l logger) Trace(msg string) { l.logger.Trace().Msg(msg) } -func (l logger) Tracef(format string, args ...interface{}) { l.logger.Trace().Msgf(format, args...) } -func (l logger) Debug(msg string) { l.logger.Debug().Msg(msg) } -func (l logger) Debugf(format string, args ...interface{}) { l.logger.Debug().Msgf(format, args...) } -func (l logger) Info(msg string) { - if strings.Contains(msg, "packetio.Buffer is full") { - //l.logger.Panic().Msg(msg) - return - } - l.logger.Info().Msg(msg) -} -func (l logger) Infof(format string, args ...interface{}) { - msg := fmt.Sprintf(format, args...) - if strings.Contains(msg, "packetio.Buffer is full") { - // l.logger.Panic().Msg(msg) - return - } - l.logger.Info().Msg(msg) -} -func (l logger) Warn(msg string) { l.logger.Warn().Msg(msg) } -func (l logger) Warnf(format string, args ...interface{}) { l.logger.Warn().Msgf(format, args...) } -func (l logger) Error(msg string) { l.logger.Error().Msg(msg) } -func (l logger) Errorf(format string, args ...interface{}) { l.logger.Error().Msgf(format, args...) } - -type loggerFactory struct { - logger zerolog.Logger -} - -func (l loggerFactory) NewLogger(subsystem string) logging.LeveledLogger { - if subsystem == "sctp" { - return nulllog{} - } - - return logger{ - subsystem: subsystem, - logger: l.logger.With().Str("subsystem", subsystem).Logger(), - } -} diff --git a/server/internal/webrtc/pionlog/factory.go b/server/internal/webrtc/pionlog/factory.go new file mode 100644 index 00000000..5a3a6beb --- /dev/null +++ b/server/internal/webrtc/pionlog/factory.go @@ -0,0 +1,27 @@ +package pionlog + +import ( + "github.com/pion/logging" + "github.com/rs/zerolog" +) + +func New(logger zerolog.Logger) Factory { + return Factory{ + Logger: logger.With().Str("submodule", "pion").Logger(), + } +} + +type Factory struct { + Logger zerolog.Logger +} + +func (l Factory) NewLogger(subsystem string) logging.LeveledLogger { + if subsystem == "sctp" { + return nulllog{} + } + + return logger{ + subsystem: subsystem, + logger: l.Logger.With().Str("subsystem", subsystem).Logger(), + } +} diff --git a/server/internal/webrtc/pionlog/logger.go b/server/internal/webrtc/pionlog/logger.go new file mode 100644 index 00000000..0bb0c292 --- /dev/null +++ b/server/internal/webrtc/pionlog/logger.go @@ -0,0 +1,66 @@ +package pionlog + +import ( + "fmt" + "strings" + + "github.com/rs/zerolog" +) + +type logger struct { + logger zerolog.Logger + subsystem string +} + +func (l logger) Trace(msg string) { + l.logger.Trace().Msg(strings.TrimSpace(msg)) +} + +func (l logger) Tracef(format string, args ...any) { + msg := fmt.Sprintf(format, args...) + l.logger.Trace().Msg(strings.TrimSpace(msg)) +} + +func (l logger) Debug(msg string) { + l.logger.Debug().Msg(strings.TrimSpace(msg)) +} + +func (l logger) Debugf(format string, args ...any) { + msg := fmt.Sprintf(format, args...) + l.logger.Debug().Msg(strings.TrimSpace(msg)) +} + +func (l logger) Info(msg string) { + if strings.Contains(msg, "duplicated packet") { + return + } + + l.logger.Info().Msg(strings.TrimSpace(msg)) +} + +func (l logger) Infof(format string, args ...any) { + msg := fmt.Sprintf(format, args...) + if strings.Contains(msg, "duplicated packet") { + return + } + + l.logger.Info().Msg(strings.TrimSpace(msg)) +} + +func (l logger) Warn(msg string) { + l.logger.Warn().Msg(strings.TrimSpace(msg)) +} + +func (l logger) Warnf(format string, args ...any) { + msg := fmt.Sprintf(format, args...) + l.logger.Warn().Msg(strings.TrimSpace(msg)) +} + +func (l logger) Error(msg string) { + l.logger.Error().Msg(strings.TrimSpace(msg)) +} + +func (l logger) Errorf(format string, args ...any) { + msg := fmt.Sprintf(format, args...) + l.logger.Error().Msg(strings.TrimSpace(msg)) +} diff --git a/server/internal/webrtc/pionlog/nullog.go b/server/internal/webrtc/pionlog/nullog.go new file mode 100644 index 00000000..2d136d04 --- /dev/null +++ b/server/internal/webrtc/pionlog/nullog.go @@ -0,0 +1,14 @@ +package pionlog + +type nulllog struct{} + +func (l nulllog) Trace(msg string) {} +func (l nulllog) Tracef(format string, args ...any) {} +func (l nulllog) Debug(msg string) {} +func (l nulllog) Debugf(format string, args ...any) {} +func (l nulllog) Info(msg string) {} +func (l nulllog) Infof(format string, args ...any) {} +func (l nulllog) Warn(msg string) {} +func (l nulllog) Warnf(format string, args ...any) {} +func (l nulllog) Error(msg string) {} +func (l nulllog) Errorf(format string, args ...any) {} diff --git a/server/internal/webrtc/webrtc.go b/server/internal/webrtc/webrtc.go index b43f4d12..2eea092f 100644 --- a/server/internal/webrtc/webrtc.go +++ b/server/internal/webrtc/webrtc.go @@ -16,6 +16,7 @@ import ( "m1k1o/neko/internal/config" "m1k1o/neko/internal/types" + "m1k1o/neko/internal/webrtc/pionlog" ) func New(sessions types.SessionManager, capture types.CaptureManager, desktop types.DesktopManager, config *config.WebRTC) *WebRTCManager { @@ -83,9 +84,7 @@ func (manager *WebRTCManager) Shutdown() error { } func (manager *WebRTCManager) initAPI() error { - logger := loggerFactory{ - logger: manager.logger, - } + logger := pionlog.New(manager.logger) settings := webrtc.SettingEngine{ LoggerFactory: logger,