github.com/whoyao/protocol@v0.0.0-20230519045905-2d8ace718ca5/logger/pionlogger/logger.go (about) 1 package pionlogger 2 3 import ( 4 "github.com/pion/logging" 5 "go.uber.org/zap/zapcore" 6 7 "github.com/whoyao/protocol/logger" 8 ) 9 10 var ( 11 pionLevel zapcore.Level 12 pionIgnoredPrefixes = map[string][]string{ 13 "ice": { 14 "pingAllCandidates called with no candidate pairs", 15 "failed to send packet: io: read/write on closed pipe", 16 "Ignoring remote candidate with tcpType active", 17 "discard message from", 18 "Failed to discover mDNS candidate", 19 "Failed to read from candidate tcp", 20 "remote mDNS candidate added, but mDNS is disabled", 21 }, 22 "pc": { 23 "Failed to accept RTCP stream is already closed", 24 "Failed to accept RTP stream is already closed", 25 "Incoming unhandled RTCP ssrc", 26 }, 27 "tcp_mux": { 28 "Error reading first packet from", 29 "error closing connection", 30 }, 31 "turn": { 32 "error when handling datagram", 33 }, 34 } 35 ) 36 37 // implements webrtc.LoggerFactory 38 type LoggerFactory struct { 39 logger logger.Logger 40 } 41 42 func NewLoggerFactory(logger logger.Logger) *LoggerFactory { 43 return &LoggerFactory{ 44 logger: logger, 45 } 46 } 47 48 func (f *LoggerFactory) NewLogger(scope string) logging.LeveledLogger { 49 return &logAdapter{ 50 logger: f.logger.WithName(scope), 51 level: pionLevel, 52 ignoredPrefixes: pionIgnoredPrefixes[scope], 53 } 54 } 55 56 func SetLogLevel(level string) { 57 pionLevel = logger.ParseZapLevel(level) 58 }