move logging to protocol (#109)

This commit is contained in:
David Colburn
2021-09-09 00:45:42 -07:00
committed by GitHub
parent 63bd531cc8
commit 2a3fb5f0e7
27 changed files with 63 additions and 95 deletions
+4 -3
View File
@@ -11,10 +11,11 @@ import (
"syscall"
"time"
"github.com/livekit/protocol/logger"
"github.com/urfave/cli/v2"
"github.com/livekit/livekit-server/pkg/config"
"github.com/livekit/livekit-server/pkg/logger"
serverlogger "github.com/livekit/livekit-server/pkg/logger"
"github.com/livekit/livekit-server/pkg/routing"
"github.com/livekit/livekit-server/pkg/service"
"github.com/livekit/livekit-server/version"
@@ -155,9 +156,9 @@ func startServer(c *cli.Context) error {
}
if conf.Development {
logger.InitDevelopment(conf.LogLevel)
serverlogger.InitDevelopment(conf.LogLevel)
} else {
logger.InitProduction(conf.LogLevel)
serverlogger.InitProduction(conf.LogLevel)
}
if cpuProfile != "" {
+4 -4
View File
@@ -7,14 +7,14 @@ require (
github.com/c9s/goprocinfo v0.0.0-20210130143923-c95fcf8c64a8
github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
github.com/gammazero/workerpool v1.1.2
github.com/go-logr/logr v1.0.0
github.com/go-logr/zapr v1.0.0
github.com/go-logr/logr v1.1.0
github.com/go-logr/zapr v1.1.0
github.com/go-redis/redis/v8 v8.11.3
github.com/google/subcommands v1.2.0 // indirect
github.com/google/wire v0.5.0
github.com/gorilla/websocket v1.4.2
github.com/jxskiss/base62 v0.0.0-20191017122030-4f11678b909b
github.com/livekit/protocol v0.8.4
github.com/livekit/protocol v0.8.6
github.com/magefile/mage v1.11.0
github.com/maxbrunsfeld/counterfeiter/v6 v6.3.0
github.com/mitchellh/go-homedir v1.1.0
@@ -39,7 +39,7 @@ require (
github.com/twitchtv/twirp v8.1.0+incompatible
github.com/urfave/cli/v2 v2.3.0
github.com/urfave/negroni v1.0.0
go.uber.org/zap v1.18.1
go.uber.org/zap v1.19.0
golang.org/x/mod v0.5.0 // indirect
golang.org/x/sys v0.0.0-20210816183151-1e6c022a8912 // indirect
golang.org/x/tools v0.1.5 // indirect
+8 -9
View File
@@ -111,11 +111,11 @@ github.com/go-kit/kit v0.10.0/go.mod h1:xUsJbQ/Fp4kEt7AFgCuvyX4a71u8h9jB8tj/ORgO
github.com/go-logfmt/logfmt v0.3.0/go.mod h1:Qt1PoO58o5twSAckw1HlFXLmHsOX5/0LbT9GBnD5lWE=
github.com/go-logfmt/logfmt v0.4.0/go.mod h1:3RMwSq7FuexP4Kalkev3ejPJsZTpXXBr9+V4qmtdjCk=
github.com/go-logfmt/logfmt v0.5.0/go.mod h1:wCYkCAKZfumFQihp8CzCvQ3paCTfi41vtzG1KdI/P7A=
github.com/go-logr/logr v1.0.0-rc1/go.mod h1:z6/tIYblkpsD+a4lm/fGIIU9mZ+XfAiaFtq7xTgseGU=
github.com/go-logr/logr v1.0.0 h1:kH951GinvFVaQgy/ki/B3YYmQtRpExGigSJg6O8z5jo=
github.com/go-logr/logr v1.0.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/zapr v1.0.0 h1:rerrgIsgykt8zVvKMVfqxI2SoYvHAFdX11er/SLZZgI=
github.com/go-logr/zapr v1.0.0/go.mod h1:t7rgfcj/l02iFgbQxqhQeoyWA9jX2+2enc4PUHF6Hp0=
github.com/go-logr/logr v1.1.0 h1:nAbevmWlS2Ic4m4+/An5NXkaGqlqpbBgdcuThZxnZyI=
github.com/go-logr/logr v1.1.0/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A=
github.com/go-logr/zapr v1.1.0 h1:rZHor2gcVGCG11UlKl+WUsfCMOOi2k/mTCDKDK6zZws=
github.com/go-logr/zapr v1.1.0/go.mod h1:YShqdLLTU346TNVu8Tvwe3bOo6gc75oZ1joeE+1lYdQ=
github.com/go-redis/redis/v8 v8.11.3 h1:GCjoYp8c+yQTJfc0n69iwSiHjvuAdruxl7elnZCxgt8=
github.com/go-redis/redis/v8 v8.11.3/go.mod h1:xNJ9xDG09FsIPwh3bWdk+0oDWHbtF9rPN0F/oD9XeKc=
github.com/go-sql-driver/mysql v1.4.0/go.mod h1:zAC/RDZ24gD3HViQzih4MyKcchzm+sOG5ZlKdlhCg5w=
@@ -246,8 +246,8 @@ github.com/lithammer/shortuuid/v3 v3.0.6 h1:pr15YQyvhiSX/qPxncFtqk+v4xLEpOZObbsY
github.com/lithammer/shortuuid/v3 v3.0.6/go.mod h1:vMk8ke37EmiewwolSO1NLW8vP4ZaKlRuDIi8tWWmAts=
github.com/livekit/ion-sfu v1.20.9 h1:Ih+tE5CXqdL1o6iXfZn+uBoddBXWceaOKVIun6aVuZM=
github.com/livekit/ion-sfu v1.20.9/go.mod h1:g8hwobZI5fvX1RXvayf4ZXkgP7spV5YGE4yTSsumpB4=
github.com/livekit/protocol v0.8.4 h1:XoH+DLno8EpT+xWor+NAVhVgmYIN+P1BV5um/nFCZAc=
github.com/livekit/protocol v0.8.4/go.mod h1:D+NoXVPVu5VRqxGe0Lt3Q1gvTm6cSRzTbYhFbRz84h8=
github.com/livekit/protocol v0.8.6 h1:pNdxWrXFXNvxF5wzsmKiiIYyrwt13dUmZiUQ4awjOEM=
github.com/livekit/protocol v0.8.6/go.mod h1:0LxJXnPRSQ05umVz1NnvRjNWNZct4fsT1OKpIUkukO0=
github.com/lucsky/cuid v1.0.2 h1:z4XlExeoderxoPj2/dxKOyPxe9RCOu7yNq9/XWxIUMQ=
github.com/lucsky/cuid v1.0.2/go.mod h1:QaaJqckboimOmhRSJXSx/+IT+VTfxfPGSo/6mfgUfmE=
github.com/lyft/protoc-gen-validate v0.0.13/go.mod h1:XbGvPuh87YZc5TdIa2/I4pLk0QoUACkjt2znoq26NVQ=
@@ -491,11 +491,10 @@ go.uber.org/multierr v1.3.0/go.mod h1:VgVr7evmIr6uPjLBxg28wmKNXyqE9akIJ5XnfpiKl+
go.uber.org/multierr v1.6.0 h1:y6IPFStTAIT5Ytl7/XYmHvzXQ7S3g/IeZW9hyZ5thw4=
go.uber.org/multierr v1.6.0/go.mod h1:cdWPpRnG4AhwMwsgIHip0KRBQjJy5kYEpYjJxpXp9iU=
go.uber.org/tools v0.0.0-20190618225709-2cfd321de3ee/go.mod h1:vJERXedbb3MVM5f9Ejo0C68/HhF8uaILCdgjnY+goOA=
go.uber.org/zap v1.8.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
go.uber.org/zap v1.10.0/go.mod h1:vwi/ZaCAaUcBkycHslxD9B2zi4UTXhF60s6SWpuDF0Q=
go.uber.org/zap v1.13.0/go.mod h1:zwrFLgMcdUuIBviXEYEH1YKNaOBnKXsx2IPda5bBwHM=
go.uber.org/zap v1.18.1 h1:CSUJ2mjFszzEWt4CdKISEuChVIXGBn3lAPwkRGyVrc4=
go.uber.org/zap v1.18.1/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI=
go.uber.org/zap v1.19.0 h1:mZQZefskPPCMIBCSEH0v2/iUqqLrYtaeqwD6FUGUnFE=
go.uber.org/zap v1.19.0/go.mod h1:xg/QME4nWcxGxrpdeYfq7UvYrLh66cuVKdrbD1XF/NI=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20181029021203-45a5f77698d3/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
+1 -1
View File
@@ -6,7 +6,7 @@ import (
"net"
"time"
"github.com/livekit/livekit-server/pkg/logger"
"github.com/livekit/protocol/logger"
"github.com/pion/stun"
"github.com/pkg/errors"
)
+15 -49
View File
@@ -1,8 +1,8 @@
package logger
package serverlogger
import (
"github.com/go-logr/logr"
"github.com/go-logr/zapr"
"github.com/livekit/protocol/logger"
"github.com/pion/ion-sfu/pkg/buffer"
"github.com/pion/ion-sfu/pkg/sfu"
"github.com/pion/logging"
@@ -11,28 +11,10 @@ import (
)
var (
// pion/ion-sfu
defaultLogger = logr.Discard()
// pion/webrtc, pion/turn
defaultFactory logging.LoggerFactory
)
// Note: already with extra depth 1
func GetLogger() logr.Logger {
if defaultLogger == logr.Discard() {
InitDevelopment("")
}
return defaultLogger
}
// Note: only pass in logr.Logger with default depth
func SetLogger(l logr.Logger) {
sfu.Logger = l.WithName("sfu")
buffer.Logger = sfu.Logger
defaultLogger = l.WithCallDepth(1).WithName("livekit")
}
func LoggerFactory() logging.LoggerFactory {
if defaultFactory == nil {
defaultFactory = logging.NewDefaultLoggerFactory()
@@ -44,6 +26,14 @@ func SetLoggerFactory(lf logging.LoggerFactory) {
defaultFactory = lf
}
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 != "" {
@@ -53,33 +43,9 @@ func initLogger(config zap.Config, level string) {
}
}
logger, _ := config.Build()
SetLogger(zapr.NewLogger(logger))
}
func InitProduction(logLevel string) {
initLogger(zap.NewProductionConfig(), logLevel)
}
func InitDevelopment(logLevel string) {
initLogger(zap.NewDevelopmentConfig(), logLevel)
}
func Debugw(msg string, keysAndValues ...interface{}) {
defaultLogger.V(1).Info(msg, keysAndValues...)
}
func Infow(msg string, keysAndValues ...interface{}) {
defaultLogger.Info(msg, keysAndValues...)
}
func Warnw(msg string, err error, keysAndValues ...interface{}) {
if err != nil {
keysAndValues = append([]interface{}{"error", err}, keysAndValues...)
}
defaultLogger.Info(msg, keysAndValues...)
}
func Errorw(msg string, err error, keysAndValues ...interface{}) {
defaultLogger.Error(err, msg, keysAndValues...)
l, _ := config.Build()
zapLogger := zapr.NewLogger(l)
sfu.Logger = zapLogger.WithName("sfu")
buffer.Logger = sfu.Logger
logger.SetLogger(zapLogger, "livekit")
}
+1 -2
View File
@@ -5,11 +5,10 @@ import (
"sync"
"time"
"github.com/livekit/protocol/logger"
livekit "github.com/livekit/protocol/proto"
"github.com/livekit/protocol/utils"
"google.golang.org/protobuf/proto"
"github.com/livekit/livekit-server/pkg/logger"
)
// a router of messages on the same node, basic implementation for local testing
+1 -1
View File
@@ -5,12 +5,12 @@ import (
"time"
"github.com/go-redis/redis/v8"
"github.com/livekit/protocol/logger"
livekit "github.com/livekit/protocol/proto"
"github.com/livekit/protocol/utils"
"github.com/pkg/errors"
"google.golang.org/protobuf/proto"
"github.com/livekit/livekit-server/pkg/logger"
"github.com/livekit/livekit-server/pkg/utils/stats"
)
+2 -2
View File
@@ -9,7 +9,7 @@ import (
"github.com/pion/webrtc/v3"
"github.com/livekit/livekit-server/pkg/config"
"github.com/livekit/livekit-server/pkg/logger"
serverlogger "github.com/livekit/livekit-server/pkg/logger"
)
const (
@@ -41,7 +41,7 @@ func NewWebRTCConfig(conf *config.Config, externalIP string) (*WebRTCConfig, err
SDPSemantics: webrtc.SDPSemanticsUnifiedPlan,
}
s := webrtc.SettingEngine{
LoggerFactory: logger.LoggerFactory(),
LoggerFactory: serverlogger.LoggerFactory(),
}
if externalIP != "" {
+1 -1
View File
@@ -6,6 +6,7 @@ import (
"sync/atomic"
"time"
"github.com/livekit/protocol/logger"
livekit "github.com/livekit/protocol/proto"
"github.com/livekit/protocol/utils"
"github.com/pion/ion-sfu/pkg/buffer"
@@ -16,7 +17,6 @@ import (
"github.com/pion/webrtc/v3/pkg/rtcerr"
"github.com/livekit/livekit-server/pkg/config"
"github.com/livekit/livekit-server/pkg/logger"
"github.com/livekit/livekit-server/pkg/rtc/types"
"github.com/livekit/livekit-server/pkg/utils/stats"
)
+1 -1
View File
@@ -7,6 +7,7 @@ import (
"sync/atomic"
"time"
"github.com/livekit/protocol/logger"
livekit "github.com/livekit/protocol/proto"
"github.com/livekit/protocol/utils"
"github.com/pion/ion-sfu/pkg/sfu"
@@ -17,7 +18,6 @@ import (
"google.golang.org/protobuf/proto"
"github.com/livekit/livekit-server/pkg/config"
"github.com/livekit/livekit-server/pkg/logger"
"github.com/livekit/livekit-server/pkg/routing"
"github.com/livekit/livekit-server/pkg/rtc/types"
"github.com/livekit/livekit-server/pkg/utils/stats"
+1 -1
View File
@@ -7,13 +7,13 @@ import (
"sync/atomic"
"time"
"github.com/livekit/protocol/logger"
livekit "github.com/livekit/protocol/proto"
"github.com/livekit/protocol/utils"
"github.com/pion/ion-sfu/pkg/buffer"
"google.golang.org/protobuf/proto"
"github.com/livekit/livekit-server/pkg/config"
"github.com/livekit/livekit-server/pkg/logger"
"github.com/livekit/livekit-server/pkg/rtc/types"
"github.com/livekit/livekit-server/pkg/utils/stats"
)
+2 -2
View File
@@ -9,7 +9,7 @@ import (
"github.com/stretchr/testify/require"
"github.com/livekit/livekit-server/pkg/config"
"github.com/livekit/livekit-server/pkg/logger"
serverlogger "github.com/livekit/livekit-server/pkg/logger"
"github.com/livekit/livekit-server/pkg/rtc"
"github.com/livekit/livekit-server/pkg/rtc/types"
"github.com/livekit/livekit-server/pkg/rtc/types/typesfakes"
@@ -23,7 +23,7 @@ const (
)
func init() {
logger.InitDevelopment("")
serverlogger.InitDevelopment("")
}
func TestJoinedState(t *testing.T) {
+1 -1
View File
@@ -7,7 +7,7 @@ import (
"net"
"syscall"
"github.com/livekit/livekit-server/pkg/logger"
"github.com/livekit/protocol/logger"
)
func checkUDPReadBuffer() {
+1 -1
View File
@@ -5,11 +5,11 @@ import (
"time"
"github.com/bep/debounce"
"github.com/livekit/protocol/logger"
livekit "github.com/livekit/protocol/proto"
"github.com/pion/interceptor"
"github.com/pion/webrtc/v3"
"github.com/livekit/livekit-server/pkg/logger"
"github.com/livekit/livekit-server/pkg/utils/stats"
)
+1 -1
View File
@@ -6,10 +6,10 @@ import (
"io"
"strings"
"github.com/livekit/protocol/logger"
livekit "github.com/livekit/protocol/proto"
"github.com/pion/webrtc/v3"
"github.com/livekit/livekit-server/pkg/logger"
"github.com/livekit/livekit-server/pkg/rtc/types"
)
+1 -1
View File
@@ -7,12 +7,12 @@ import (
"time"
"github.com/gammazero/workerpool"
"github.com/livekit/protocol/logger"
livekit "github.com/livekit/protocol/proto"
"github.com/livekit/protocol/utils"
"github.com/livekit/protocol/webhook"
"github.com/livekit/livekit-server/pkg/config"
"github.com/livekit/livekit-server/pkg/logger"
"github.com/livekit/livekit-server/pkg/routing"
"github.com/livekit/livekit-server/pkg/rtc"
"github.com/livekit/livekit-server/pkg/rtc/types"
+1 -1
View File
@@ -8,10 +8,10 @@ import (
"strings"
"github.com/gorilla/websocket"
"github.com/livekit/protocol/logger"
livekit "github.com/livekit/protocol/proto"
"github.com/livekit/livekit-server/pkg/config"
"github.com/livekit/livekit-server/pkg/logger"
"github.com/livekit/livekit-server/pkg/routing"
"github.com/livekit/livekit-server/pkg/rtc"
"github.com/livekit/livekit-server/pkg/rtc/types"
+1 -1
View File
@@ -11,6 +11,7 @@ import (
"time"
"github.com/livekit/protocol/auth"
"github.com/livekit/protocol/logger"
livekit "github.com/livekit/protocol/proto"
"github.com/livekit/protocol/utils"
"github.com/pion/turn/v2"
@@ -18,7 +19,6 @@ import (
"github.com/urfave/negroni"
"github.com/livekit/livekit-server/pkg/config"
"github.com/livekit/livekit-server/pkg/logger"
"github.com/livekit/livekit-server/pkg/routing"
"github.com/livekit/livekit-server/version"
)
+3 -2
View File
@@ -6,11 +6,12 @@ import (
"net"
"strconv"
"github.com/livekit/protocol/logger"
"github.com/pion/turn/v2"
"github.com/pkg/errors"
"github.com/livekit/livekit-server/pkg/config"
"github.com/livekit/livekit-server/pkg/logger"
serverlogger "github.com/livekit/livekit-server/pkg/logger"
"github.com/livekit/livekit-server/pkg/routing"
)
@@ -34,7 +35,7 @@ func NewTurnServer(conf *config.Config, roomStore RoomStore, node routing.LocalN
serverConfig := turn.ServerConfig{
Realm: livekitRealm,
AuthHandler: newTurnAuthHandler(roomStore),
LoggerFactory: logger.LoggerFactory(),
LoggerFactory: serverlogger.LoggerFactory(),
}
relayAddrGen := &turn.RelayAddressGeneratorPortRange{
RelayAddress: net.ParseIP(node.Ip),
+1 -1
View File
@@ -10,13 +10,13 @@ import (
"github.com/go-redis/redis/v8"
"github.com/google/wire"
"github.com/livekit/protocol/auth"
"github.com/livekit/protocol/logger"
livekit "github.com/livekit/protocol/proto"
"github.com/livekit/protocol/utils"
"github.com/livekit/protocol/webhook"
"github.com/pkg/errors"
"github.com/livekit/livekit-server/pkg/config"
"github.com/livekit/livekit-server/pkg/logger"
"github.com/livekit/livekit-server/pkg/routing"
)
+1 -1
View File
@@ -5,11 +5,11 @@ import (
"time"
"github.com/gorilla/websocket"
"github.com/livekit/protocol/logger"
livekit "github.com/livekit/protocol/proto"
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto"
"github.com/livekit/livekit-server/pkg/logger"
"github.com/livekit/livekit-server/pkg/rtc/types"
)
+1 -1
View File
@@ -5,7 +5,7 @@ import (
"testing"
"time"
"github.com/livekit/livekit-server/pkg/logger"
"github.com/livekit/protocol/logger"
)
var (
+2 -1
View File
@@ -21,7 +21,8 @@ import (
"google.golang.org/protobuf/encoding/protojson"
"google.golang.org/protobuf/proto"
"github.com/livekit/livekit-server/pkg/logger"
"github.com/livekit/protocol/logger"
"github.com/livekit/livekit-server/pkg/rtc"
)
+1 -1
View File
@@ -12,7 +12,7 @@ import (
"github.com/pion/webrtc/v3/pkg/media/ivfreader"
"github.com/pion/webrtc/v3/pkg/media/oggreader"
"github.com/livekit/livekit-server/pkg/logger"
"github.com/livekit/protocol/logger"
)
// Writes a file to an RTP track.
+3 -2
View File
@@ -10,12 +10,13 @@ import (
"github.com/go-redis/redis/v8"
"github.com/livekit/protocol/auth"
"github.com/livekit/protocol/logger"
livekit "github.com/livekit/protocol/proto"
"github.com/livekit/protocol/utils"
"github.com/twitchtv/twirp"
"github.com/livekit/livekit-server/pkg/config"
"github.com/livekit/livekit-server/pkg/logger"
serverlogger "github.com/livekit/livekit-server/pkg/logger"
"github.com/livekit/livekit-server/pkg/routing"
"github.com/livekit/livekit-server/pkg/service"
"github.com/livekit/livekit-server/pkg/testutils"
@@ -42,7 +43,7 @@ var (
)
func init() {
logger.InitDevelopment("")
serverlogger.InitDevelopment("")
}
func setupSingleNodeTest(name string, roomName string) (*service.LivekitServer, func()) {
+3 -3
View File
@@ -4,11 +4,11 @@ import (
"testing"
"time"
"github.com/livekit/livekit-server/pkg/testutils"
testclient "github.com/livekit/livekit-server/test/client"
"github.com/livekit/protocol/logger"
"github.com/stretchr/testify/require"
"github.com/livekit/livekit-server/pkg/logger"
"github.com/livekit/livekit-server/pkg/testutils"
testclient "github.com/livekit/livekit-server/test/client"
)
// a scenario with lots of clients connecting, publishing, and leaving at random periods
+1 -1
View File
@@ -9,6 +9,7 @@ import (
"testing"
"github.com/livekit/protocol/auth"
"github.com/livekit/protocol/logger"
livekit "github.com/livekit/protocol/proto"
"github.com/livekit/protocol/utils"
"github.com/livekit/protocol/webhook"
@@ -16,7 +17,6 @@ import (
"google.golang.org/protobuf/encoding/protojson"
"github.com/livekit/livekit-server/pkg/config"
"github.com/livekit/livekit-server/pkg/logger"
"github.com/livekit/livekit-server/pkg/routing"
"github.com/livekit/livekit-server/pkg/service"
"github.com/livekit/livekit-server/pkg/testutils"