pionlog to own folder.

This commit is contained in:
Miroslav Šedivý 2021-09-02 20:48:15 +02:00
parent 1dab0bd859
commit e812cb9fbf
5 changed files with 45 additions and 36 deletions

View File

@ -19,6 +19,7 @@ import (
"demodesk/neko/internal/types/event"
"demodesk/neko/internal/types/message"
"demodesk/neko/internal/webrtc/cursor"
"demodesk/neko/internal/webrtc/pionlog"
)
// the duration without network activity before a Agent is considered disconnected. Default is 5 Seconds
@ -237,10 +238,9 @@ func (manager *WebRTCManagerCtx) CreatePeer(session types.Session, videoID strin
peer := &WebRTCPeerCtx{
logger: logger,
api: api,
connection: connection,
changeVideo: changeVideo,
dataChannel: dataChannel,
changeVideo: changeVideo,
iceTrickle: manager.config.ICETrickle,
}
@ -373,9 +373,7 @@ func (manager *WebRTCManagerCtx) mediaEngine(videoID string) (*webrtc.MediaEngin
func (manager *WebRTCManagerCtx) apiSettings(logger zerolog.Logger) webrtc.SettingEngine {
settings := webrtc.SettingEngine{
LoggerFactory: loggerFactory{
logger: logger,
},
LoggerFactory: pionlog.New(logger),
}
//nolint

View File

@ -10,7 +10,6 @@ import (
type WebRTCPeerCtx struct {
mu sync.Mutex
logger zerolog.Logger
api *webrtc.API
connection *webrtc.PeerConnection
dataChannel *webrtc.DataChannel
changeVideo func(videoID string) error

View File

@ -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(),
}
}

View File

@ -1,26 +1,12 @@
package webrtc
package pionlog
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
@ -69,18 +55,3 @@ func (l logger) Errorf(format string, args ...interface{}) {
msg := fmt.Sprintf(format, args...)
l.logger.Error().Msg(strings.TrimSpace(msg))
}
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("submodule", "pion").Str("subsystem", subsystem).Logger(),
}
}

View File

@ -0,0 +1,14 @@
package pionlog
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{}) {}