Improve logging, hook up ion with zap logger
This commit is contained in:
@@ -16,7 +16,7 @@ require (
|
|||||||
github.com/mitchellh/go-homedir v1.1.0
|
github.com/mitchellh/go-homedir v1.1.0
|
||||||
github.com/pion/ice/v2 v2.1.7
|
github.com/pion/ice/v2 v2.1.7
|
||||||
github.com/pion/interceptor v0.0.12
|
github.com/pion/interceptor v0.0.12
|
||||||
github.com/pion/ion-sfu v1.10.3
|
github.com/pion/ion-sfu v1.10.5
|
||||||
github.com/pion/logging v0.2.2
|
github.com/pion/logging v0.2.2
|
||||||
github.com/pion/rtcp v1.2.6
|
github.com/pion/rtcp v1.2.6
|
||||||
github.com/pion/rtp v1.6.5
|
github.com/pion/rtp v1.6.5
|
||||||
|
|||||||
@@ -230,8 +230,6 @@ github.com/lightstep/lightstep-tracer-common/golang/gogo v0.0.0-20190605223551-b
|
|||||||
github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4=
|
github.com/lightstep/lightstep-tracer-go v0.18.1/go.mod h1:jlF1pusYV4pidLvZ+XD0UBX0ZE6WURAspgAczcDHrL4=
|
||||||
github.com/lithammer/shortuuid/v3 v3.0.6 h1:pr15YQyvhiSX/qPxncFtqk+v4xLEpOZObbsY/mKrcvA=
|
github.com/lithammer/shortuuid/v3 v3.0.6 h1:pr15YQyvhiSX/qPxncFtqk+v4xLEpOZObbsY/mKrcvA=
|
||||||
github.com/lithammer/shortuuid/v3 v3.0.6/go.mod h1:vMk8ke37EmiewwolSO1NLW8vP4ZaKlRuDIi8tWWmAts=
|
github.com/lithammer/shortuuid/v3 v3.0.6/go.mod h1:vMk8ke37EmiewwolSO1NLW8vP4ZaKlRuDIi8tWWmAts=
|
||||||
github.com/livekit/protocol v0.5.1 h1:RSX0sQM2+NK2kCHTg/n6wPf0d3qYskc611GYV3h+5+8=
|
|
||||||
github.com/livekit/protocol v0.5.1/go.mod h1:wo3CGfYB7XMF8GoVJAfTARrYSP/ombi+sbLl6AYdKP0=
|
|
||||||
github.com/livekit/protocol v0.5.2 h1:jYj+50gKBrtJ1q6iEVdHDruHVllA1xtOhiM1/YKqgMk=
|
github.com/livekit/protocol v0.5.2 h1:jYj+50gKBrtJ1q6iEVdHDruHVllA1xtOhiM1/YKqgMk=
|
||||||
github.com/livekit/protocol v0.5.2/go.mod h1:wo3CGfYB7XMF8GoVJAfTARrYSP/ombi+sbLl6AYdKP0=
|
github.com/livekit/protocol v0.5.2/go.mod h1:wo3CGfYB7XMF8GoVJAfTARrYSP/ombi+sbLl6AYdKP0=
|
||||||
github.com/lucsky/cuid v1.0.2 h1:z4XlExeoderxoPj2/dxKOyPxe9RCOu7yNq9/XWxIUMQ=
|
github.com/lucsky/cuid v1.0.2 h1:z4XlExeoderxoPj2/dxKOyPxe9RCOu7yNq9/XWxIUMQ=
|
||||||
@@ -317,10 +315,8 @@ github.com/pion/ice/v2 v2.1.7 h1:FjgDfUNrVYTxQabJrkBX6ld12tvYbgzHenqPh3PJF6E=
|
|||||||
github.com/pion/ice/v2 v2.1.7/go.mod h1:kV4EODVD5ux2z8XncbLHIOtcXKtYXVgLVCeVqnpoeP0=
|
github.com/pion/ice/v2 v2.1.7/go.mod h1:kV4EODVD5ux2z8XncbLHIOtcXKtYXVgLVCeVqnpoeP0=
|
||||||
github.com/pion/interceptor v0.0.12 h1:eC1iVneBIAQJEfaNAfDqAncJWhMDAnaXPRCJsltdokE=
|
github.com/pion/interceptor v0.0.12 h1:eC1iVneBIAQJEfaNAfDqAncJWhMDAnaXPRCJsltdokE=
|
||||||
github.com/pion/interceptor v0.0.12/go.mod h1:qzeuWuD/ZXvPqOnxNcnhWfkCZ2e1kwwslicyyPnhoK4=
|
github.com/pion/interceptor v0.0.12/go.mod h1:qzeuWuD/ZXvPqOnxNcnhWfkCZ2e1kwwslicyyPnhoK4=
|
||||||
github.com/pion/ion-log v1.0.1 h1:D3kW75Xa6mxxTSNUP0xoYeDa/C+hINdB04XjicJ7H0Q=
|
github.com/pion/ion-sfu v1.10.5 h1:8VH7IwEEyAr/RiHtAyM2vSmaP0oGKGVD3sFlFCVQ6cg=
|
||||||
github.com/pion/ion-log v1.0.1/go.mod h1:jwcla9KoB9bB/4FxYDSRJPcPYSLp5XiUUMnOLaqwl4E=
|
github.com/pion/ion-sfu v1.10.5/go.mod h1:Wx6b4qGUjvSo1kGl+/fHl0ZF48g2IJOjzUFg0yCo9qY=
|
||||||
github.com/pion/ion-sfu v1.10.3 h1:/kliY0pRoE87v+PF3k472u3fVDIBA+tK/xJSaltRUDQ=
|
|
||||||
github.com/pion/ion-sfu v1.10.3/go.mod h1:xdD571H5V7bHaHg6gcg/mqnuXPIljv5In6U5O+576Xs=
|
|
||||||
github.com/pion/logging v0.2.2 h1:M9+AIj/+pxNsDfAT64+MAVgJO0rsyLnoJKCqf//DoeY=
|
github.com/pion/logging v0.2.2 h1:M9+AIj/+pxNsDfAT64+MAVgJO0rsyLnoJKCqf//DoeY=
|
||||||
github.com/pion/logging v0.2.2/go.mod h1:k0/tDVsRCX2Mb2ZEmTqNa7CWsQPc+YYCB7Q+5pahoms=
|
github.com/pion/logging v0.2.2/go.mod h1:k0/tDVsRCX2Mb2ZEmTqNa7CWsQPc+YYCB7Q+5pahoms=
|
||||||
github.com/pion/mdns v0.0.5 h1:Q2oj/JB3NqfzY9xGZ1fPzZzK7sDSD8rZPOvcIQ10BCw=
|
github.com/pion/mdns v0.0.5 h1:Q2oj/JB3NqfzY9xGZ1fPzZzK7sDSD8rZPOvcIQ10BCw=
|
||||||
|
|||||||
+25
-20
@@ -1,21 +1,27 @@
|
|||||||
package logger
|
package logger
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"github.com/go-logr/zapr"
|
||||||
|
"github.com/pion/ion-sfu/pkg/buffer"
|
||||||
|
"github.com/pion/ion-sfu/pkg/sfu"
|
||||||
"go.uber.org/zap"
|
"go.uber.org/zap"
|
||||||
"go.uber.org/zap/zapcore"
|
"go.uber.org/zap/zapcore"
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
logger *zap.SugaredLogger
|
wrappedLogger *zap.SugaredLogger
|
||||||
|
// zap logger
|
||||||
|
defaultLogger *zap.Logger
|
||||||
)
|
)
|
||||||
|
|
||||||
func getLogger() *zap.SugaredLogger {
|
func GetLogger() *zap.Logger {
|
||||||
if logger == nil {
|
if defaultLogger == nil {
|
||||||
InitDevelopment("")
|
InitDevelopment("")
|
||||||
}
|
}
|
||||||
return logger
|
return defaultLogger
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// valid levels: debug, info, warn, error, fatal, panic
|
||||||
func initLogger(config zap.Config, level string) {
|
func initLogger(config zap.Config, level string) {
|
||||||
if level != "" {
|
if level != "" {
|
||||||
lvl := zapcore.Level(0)
|
lvl := zapcore.Level(0)
|
||||||
@@ -23,8 +29,14 @@ func initLogger(config zap.Config, level string) {
|
|||||||
config.Level = zap.NewAtomicLevelAt(lvl)
|
config.Level = zap.NewAtomicLevelAt(lvl)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// skip one level to remove this helper file
|
||||||
l, _ := config.Build(zap.AddCallerSkip(1))
|
l, _ := config.Build(zap.AddCallerSkip(1))
|
||||||
logger = l.Sugar()
|
wrappedLogger = l.Sugar()
|
||||||
|
|
||||||
|
defaultLogger, _ = config.Build()
|
||||||
|
ionLogger := zapr.NewLogger(defaultLogger)
|
||||||
|
sfu.Logger = ionLogger
|
||||||
|
buffer.Logger = ionLogger
|
||||||
}
|
}
|
||||||
|
|
||||||
func InitProduction(logLevel string) {
|
func InitProduction(logLevel string) {
|
||||||
@@ -36,42 +48,35 @@ func InitDevelopment(logLevel string) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func Debugw(msg string, keysAndValues ...interface{}) {
|
func Debugw(msg string, keysAndValues ...interface{}) {
|
||||||
if logger == nil {
|
if wrappedLogger == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
logger.Debugw(msg, keysAndValues...)
|
wrappedLogger.Debugw(msg, keysAndValues...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Infow(msg string, keysAndValues ...interface{}) {
|
func Infow(msg string, keysAndValues ...interface{}) {
|
||||||
if logger == nil {
|
if wrappedLogger == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
logger.Infow(msg, keysAndValues...)
|
wrappedLogger.Infow(msg, keysAndValues...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Warnw(msg string, err error, keysAndValues ...interface{}) {
|
func Warnw(msg string, err error, keysAndValues ...interface{}) {
|
||||||
if logger == nil {
|
if wrappedLogger == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
keysAndValues = append([]interface{}{"error", err}, keysAndValues...)
|
keysAndValues = append([]interface{}{"error", err}, keysAndValues...)
|
||||||
}
|
}
|
||||||
logger.Warnw(msg, keysAndValues...)
|
wrappedLogger.Warnw(msg, keysAndValues...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Errorw(msg string, err error, keysAndValues ...interface{}) {
|
func Errorw(msg string, err error, keysAndValues ...interface{}) {
|
||||||
if logger == nil {
|
if wrappedLogger == nil {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if err != nil {
|
if err != nil {
|
||||||
keysAndValues = append([]interface{}{"error", err}, keysAndValues...)
|
keysAndValues = append([]interface{}{"error", err}, keysAndValues...)
|
||||||
}
|
}
|
||||||
logger.Errorw(msg, keysAndValues...)
|
wrappedLogger.Errorw(msg, keysAndValues...)
|
||||||
}
|
|
||||||
|
|
||||||
func Desugar() *zap.Logger {
|
|
||||||
if logger == nil {
|
|
||||||
getLogger()
|
|
||||||
}
|
|
||||||
return logger.Desugar()
|
|
||||||
}
|
}
|
||||||
|
|||||||
+26
-23
@@ -39,7 +39,8 @@ type ReceiverConfig struct {
|
|||||||
// number of packets to buffer up
|
// number of packets to buffer up
|
||||||
const readBufferSize = 50
|
const readBufferSize = 50
|
||||||
|
|
||||||
func NewWebRTCConfig(conf *config.RTCConfig, externalIP string) (*WebRTCConfig, error) {
|
func NewWebRTCConfig(conf *config.Config, externalIP string) (*WebRTCConfig, error) {
|
||||||
|
rtcConf := conf.RTC
|
||||||
c := webrtc.Configuration{
|
c := webrtc.Configuration{
|
||||||
SDPSemantics: webrtc.SDPSemanticsUnifiedPlan,
|
SDPSemantics: webrtc.SDPSemanticsUnifiedPlan,
|
||||||
}
|
}
|
||||||
@@ -48,7 +49,7 @@ func NewWebRTCConfig(conf *config.RTCConfig, externalIP string) (*WebRTCConfig,
|
|||||||
lkLogger := loggerFactory.NewLogger("livekit-mux")
|
lkLogger := loggerFactory.NewLogger("livekit-mux")
|
||||||
|
|
||||||
iceUrls := make([]string, 0)
|
iceUrls := make([]string, 0)
|
||||||
for _, stunServer := range conf.StunServers {
|
for _, stunServer := range rtcConf.StunServers {
|
||||||
iceUrls = append(iceUrls, fmt.Sprintf("stun:%s", stunServer))
|
iceUrls = append(iceUrls, fmt.Sprintf("stun:%s", stunServer))
|
||||||
}
|
}
|
||||||
c.ICEServers = []webrtc.ICEServer{
|
c.ICEServers = []webrtc.ICEServer{
|
||||||
@@ -56,18 +57,18 @@ func NewWebRTCConfig(conf *config.RTCConfig, externalIP string) (*WebRTCConfig,
|
|||||||
URLs: iceUrls,
|
URLs: iceUrls,
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
if conf.UseExternalIP && externalIP != "" {
|
if rtcConf.UseExternalIP && externalIP != "" {
|
||||||
s.SetNAT1To1IPs([]string{externalIP}, webrtc.ICECandidateTypeHost)
|
s.SetNAT1To1IPs([]string{externalIP}, webrtc.ICECandidateTypeHost)
|
||||||
}
|
}
|
||||||
|
|
||||||
if conf.PacketBufferSize == 0 {
|
if rtcConf.PacketBufferSize == 0 {
|
||||||
conf.PacketBufferSize = 500
|
rtcConf.PacketBufferSize = 500
|
||||||
}
|
}
|
||||||
bufferFactory := buffer.NewBufferFactory(conf.PacketBufferSize, zapr.NewLogger(logger.Desugar()))
|
bufferFactory := buffer.NewBufferFactory(rtcConf.PacketBufferSize, zapr.NewLogger(logger.GetLogger()))
|
||||||
s.BufferFactory = bufferFactory.GetOrNew
|
s.BufferFactory = bufferFactory.GetOrNew
|
||||||
|
|
||||||
networkTypes := make([]webrtc.NetworkType, 0, 4)
|
networkTypes := make([]webrtc.NetworkType, 0, 4)
|
||||||
if !conf.ForceTCP {
|
if !rtcConf.ForceTCP {
|
||||||
networkTypes = append(networkTypes,
|
networkTypes = append(networkTypes,
|
||||||
webrtc.NetworkTypeUDP4,
|
webrtc.NetworkTypeUDP4,
|
||||||
)
|
)
|
||||||
@@ -76,9 +77,9 @@ func NewWebRTCConfig(conf *config.RTCConfig, externalIP string) (*WebRTCConfig,
|
|||||||
var udpMux *ice.UDPMuxDefault
|
var udpMux *ice.UDPMuxDefault
|
||||||
var udpMuxConn *net.UDPConn
|
var udpMuxConn *net.UDPConn
|
||||||
var err error
|
var err error
|
||||||
if conf.UDPPort != 0 {
|
if rtcConf.UDPPort != 0 {
|
||||||
udpMuxConn, err = net.ListenUDP("udp4", &net.UDPAddr{
|
udpMuxConn, err = net.ListenUDP("udp4", &net.UDPAddr{
|
||||||
Port: int(conf.UDPPort),
|
Port: int(rtcConf.UDPPort),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -91,30 +92,32 @@ func NewWebRTCConfig(conf *config.RTCConfig, externalIP string) (*WebRTCConfig,
|
|||||||
UDPConn: udpMuxConn,
|
UDPConn: udpMuxConn,
|
||||||
})
|
})
|
||||||
s.SetICEUDPMux(udpMux)
|
s.SetICEUDPMux(udpMux)
|
||||||
val, err := checkUDPReadBuffer()
|
if !conf.Development {
|
||||||
if err == nil {
|
val, err := checkUDPReadBuffer()
|
||||||
if val < minUDPBufferSize {
|
if err == nil {
|
||||||
logger.Warnw("UDP receive buffer is too small for a production set-up", nil,
|
if val < minUDPBufferSize {
|
||||||
"current", val,
|
logger.Warnw("UDP receive buffer is too small for a production set-up", nil,
|
||||||
"suggested", minUDPBufferSize)
|
"current", val,
|
||||||
} else {
|
"suggested", minUDPBufferSize)
|
||||||
logger.Debugw("UDP receive buffer size", "current", val)
|
} else {
|
||||||
|
logger.Debugw("UDP receive buffer size", "current", val)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else if conf.ICEPortRangeStart != 0 && conf.ICEPortRangeEnd != 0 {
|
} else if rtcConf.ICEPortRangeStart != 0 && rtcConf.ICEPortRangeEnd != 0 {
|
||||||
if err := s.SetEphemeralUDPPortRange(uint16(conf.ICEPortRangeStart), uint16(conf.ICEPortRangeEnd)); err != nil {
|
if err := s.SetEphemeralUDPPortRange(uint16(rtcConf.ICEPortRangeStart), uint16(rtcConf.ICEPortRangeEnd)); err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// use TCP mux when it's set
|
// use TCP mux when it's set
|
||||||
var tcpListener *net.TCPListener
|
var tcpListener *net.TCPListener
|
||||||
if conf.TCPPort != 0 {
|
if rtcConf.TCPPort != 0 {
|
||||||
networkTypes = append(networkTypes,
|
networkTypes = append(networkTypes,
|
||||||
webrtc.NetworkTypeTCP4,
|
webrtc.NetworkTypeTCP4,
|
||||||
)
|
)
|
||||||
tcpListener, err = net.ListenTCP("tcp4", &net.TCPAddr{
|
tcpListener, err = net.ListenTCP("tcp4", &net.TCPAddr{
|
||||||
Port: int(conf.TCPPort),
|
Port: int(rtcConf.TCPPort),
|
||||||
})
|
})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@@ -134,8 +137,8 @@ func NewWebRTCConfig(conf *config.RTCConfig, externalIP string) (*WebRTCConfig,
|
|||||||
SettingEngine: s,
|
SettingEngine: s,
|
||||||
BufferFactory: bufferFactory,
|
BufferFactory: bufferFactory,
|
||||||
Receiver: ReceiverConfig{
|
Receiver: ReceiverConfig{
|
||||||
packetBufferSize: conf.PacketBufferSize,
|
packetBufferSize: rtcConf.PacketBufferSize,
|
||||||
maxBitrate: conf.MaxBitrate,
|
maxBitrate: rtcConf.MaxBitrate,
|
||||||
},
|
},
|
||||||
UDPMux: udpMux,
|
UDPMux: udpMux,
|
||||||
UDPMuxConn: udpMuxConn,
|
UDPMuxConn: udpMuxConn,
|
||||||
|
|||||||
+1
-1
@@ -122,7 +122,7 @@ func RecoverSilent() {
|
|||||||
|
|
||||||
func Recover() {
|
func Recover() {
|
||||||
if r := recover(); r != nil {
|
if r := recover(); r != nil {
|
||||||
log := logger.Desugar().WithOptions(zap.AddCallerSkip(1))
|
log := logger.GetLogger().WithOptions(zap.AddCallerSkip(1))
|
||||||
log.Error("recovered panic", zap.Any("error", r))
|
log.Error("recovered panic", zap.Any("error", r))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ type RoomManager struct {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func NewRoomManager(rp RoomStore, router routing.Router, currentNode routing.LocalNode, selector routing.NodeSelector, conf *config.Config) (*RoomManager, error) {
|
func NewRoomManager(rp RoomStore, router routing.Router, currentNode routing.LocalNode, selector routing.NodeSelector, conf *config.Config) (*RoomManager, error) {
|
||||||
rtcConf, err := rtc.NewWebRTCConfig(&conf.RTC, currentNode.Ip)
|
rtcConf, err := rtc.NewWebRTCConfig(conf, currentNode.Ip)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,12 +28,7 @@ func NewRTCService(conf *config.Config, roomStore RoomStore, roomManager *RoomMa
|
|||||||
s := &RTCService{
|
s := &RTCService{
|
||||||
router: router,
|
router: router,
|
||||||
roomManager: roomManager,
|
roomManager: roomManager,
|
||||||
upgrader: websocket.Upgrader{
|
upgrader: websocket.Upgrader{},
|
||||||
// increase buffer size to avoid errors such as
|
|
||||||
// read: connection reset by peer
|
|
||||||
// ReadBufferSize: 10240,
|
|
||||||
// WriteBufferSize: 10240,
|
|
||||||
},
|
|
||||||
currentNode: currentNode,
|
currentNode: currentNode,
|
||||||
isDev: conf.Development,
|
isDev: conf.Development,
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ var ServiceSet = wire.NewSet(
|
|||||||
)
|
)
|
||||||
|
|
||||||
func handleError(w http.ResponseWriter, status int, msg string) {
|
func handleError(w http.ResponseWriter, status int, msg string) {
|
||||||
l := logger.Desugar().WithOptions(zap.AddCallerSkip(1))
|
l := logger.GetLogger().WithOptions(zap.AddCallerSkip(1))
|
||||||
l.Debug("error handling request", zap.String("error", msg), zap.Int("status", status))
|
l.Debug("error handling request", zap.String("error", msg), zap.Int("status", status))
|
||||||
w.WriteHeader(status)
|
w.WriteHeader(status)
|
||||||
_, _ = w.Write([]byte(msg))
|
_, _ = w.Write([]byte(msg))
|
||||||
|
|||||||
+1
-1
@@ -1,3 +1,3 @@
|
|||||||
package version
|
package version
|
||||||
|
|
||||||
const Version = "0.9.8"
|
const Version = "0.9.9"
|
||||||
|
|||||||
Reference in New Issue
Block a user