neko/internal/webrtc/logger.go

87 lines
2.3 KiB
Go
Raw Normal View History

package webrtc
import (
"fmt"
"strings"
"github.com/pion/logging"
"github.com/rs/zerolog"
)
2021-02-15 02:40:17 +13:00
type nulllog struct{}
2021-02-15 02:40:17 +13:00
func (l nulllog) Trace(msg string) {}
func (l nulllog) Tracef(format string, args ...interface{}) {}
2021-02-15 02:40:17 +13:00
func (l nulllog) Debug(msg string) {}
func (l nulllog) Debugf(format string, args ...interface{}) {}
2021-02-15 02:40:17 +13:00
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
}
2020-11-02 04:09:48 +13:00
func (l logger) Trace(msg string) {
2020-11-15 02:52:15 +13:00
l.logger.Trace().Msg(strings.TrimSpace(msg))
2020-11-02 04:09:48 +13:00
}
func (l logger) Tracef(format string, args ...interface{}) {
2020-11-15 02:52:15 +13:00
msg := fmt.Sprintf(format, args...)
l.logger.Trace().Msg(strings.TrimSpace(msg))
2020-11-02 04:09:48 +13:00
}
func (l logger) Debug(msg string) {
2020-11-15 02:52:15 +13:00
l.logger.Debug().Msg(strings.TrimSpace(msg))
2020-11-02 04:09:48 +13:00
}
func (l logger) Debugf(format string, args ...interface{}) {
2020-11-15 02:52:15 +13:00
msg := fmt.Sprintf(format, args...)
l.logger.Debug().Msg(strings.TrimSpace(msg))
2020-11-02 04:09:48 +13:00
}
func (l logger) Info(msg string) {
2021-01-14 09:36:43 +13:00
if strings.Contains(msg, "duplicated packet") {
return
}
2021-01-14 09:36:43 +13:00
2020-11-15 02:52:15 +13:00
l.logger.Info().Msg(strings.TrimSpace(msg))
}
func (l logger) Infof(format string, args ...interface{}) {
msg := fmt.Sprintf(format, args...)
2021-01-14 09:36:43 +13:00
if strings.Contains(msg, "duplicated packet") {
return
}
2021-01-14 09:36:43 +13:00
2020-11-15 02:52:15 +13:00
l.logger.Info().Msg(strings.TrimSpace(msg))
}
2020-11-02 04:09:48 +13:00
func (l logger) Warn(msg string) {
2020-11-15 02:52:15 +13:00
l.logger.Warn().Msg(strings.TrimSpace(msg))
2020-11-02 04:09:48 +13:00
}
func (l logger) Warnf(format string, args ...interface{}) {
2020-11-15 02:52:15 +13:00
msg := fmt.Sprintf(format, args...)
l.logger.Warn().Msg(strings.TrimSpace(msg))
2020-11-02 04:09:48 +13:00
}
func (l logger) Error(msg string) {
2020-11-15 02:52:15 +13:00
l.logger.Error().Msg(strings.TrimSpace(msg))
2020-11-02 04:09:48 +13:00
}
func (l logger) Errorf(format string, args ...interface{}) {
2020-11-15 02:52:15 +13:00
msg := fmt.Sprintf(format, args...)
l.logger.Error().Msg(strings.TrimSpace(msg))
2020-11-02 04:09:48 +13:00
}
type loggerFactory struct {
logger zerolog.Logger
}
func (l loggerFactory) NewLogger(subsystem string) logging.LeveledLogger {
if subsystem == "sctp" {
return nulllog{}
}
return logger{
subsystem: subsystem,
2021-08-30 04:59:46 +12:00
logger: l.logger.With().Str("submodule", "pion").Str("subsystem", subsystem).Logger(),
}
}