@@ -16,7 +16,6 @@ package pionlogger
1616
1717import (
1818 "fmt"
19- "strings"
2019
2120 "go.uber.org/atomic"
2221 "go.uber.org/zap"
@@ -34,16 +33,16 @@ const (
3433// implements webrtc.LeveledLogger
3534type zapLogAdapter struct {
3635 state atomic.Uint32
37- logger logger.ZapLogger
36+ logger logger.Logger
3837 level zapcore.LevelEnabler
3938 scope string
40- ignoredPrefixes [] string
39+ ignoredPrefixes prefixSet
4140}
4241
4342func (l * zapLogAdapter ) init () {
4443 for l .state .Load () != zapLogAdapterStateReady {
4544 if l .state .CompareAndSwap (zapLogAdapterStateCreated , zapLogAdapterStateBuilding ) {
46- l .logger = l .logger .WithComponent (formatComponent (l .scope )).WithCallDepth (1 ).(logger. ZapLogger )
45+ l .logger = l .logger .WithComponent (formatComponent (l .scope )).WithCallDepth (1 )
4746 l .state .Store (zapLogAdapterStateReady )
4847 }
4948 }
@@ -65,7 +64,7 @@ func (l *zapLogAdapter) Tracef(format string, args ...interface{}) {
6564
6665func (l * zapLogAdapter ) Debug (msg string ) {
6766 if l .level .Enabled (zap .DebugLevel ) {
68- if ! l .shouldIgnore (msg ) {
67+ if ! l .ignoredPrefixes . Match (msg ) {
6968 l .init ()
7069 l .logger .Debugw (msg )
7170 }
@@ -75,7 +74,7 @@ func (l *zapLogAdapter) Debug(msg string) {
7574func (l * zapLogAdapter ) Debugf (format string , args ... interface {}) {
7675 if l .level .Enabled (zap .DebugLevel ) {
7776 msg := fmt .Sprintf (format , args ... )
78- if ! l .shouldIgnore (msg ) {
77+ if ! l .ignoredPrefixes . Match (msg ) {
7978 l .init ()
8079 l .logger .Debugw (msg )
8180 }
@@ -84,7 +83,7 @@ func (l *zapLogAdapter) Debugf(format string, args ...interface{}) {
8483
8584func (l * zapLogAdapter ) Info (msg string ) {
8685 if l .level .Enabled (zap .InfoLevel ) {
87- if ! l .shouldIgnore (msg ) {
86+ if ! l .ignoredPrefixes . Match (msg ) {
8887 l .init ()
8988 l .logger .Infow (msg )
9089 }
@@ -94,7 +93,7 @@ func (l *zapLogAdapter) Info(msg string) {
9493func (l * zapLogAdapter ) Infof (format string , args ... interface {}) {
9594 if l .level .Enabled (zap .InfoLevel ) {
9695 msg := fmt .Sprintf (format , args ... )
97- if ! l .shouldIgnore (msg ) {
96+ if ! l .ignoredPrefixes . Match (msg ) {
9897 l .init ()
9998 l .logger .Infow (msg )
10099 }
@@ -103,7 +102,7 @@ func (l *zapLogAdapter) Infof(format string, args ...interface{}) {
103102
104103func (l * zapLogAdapter ) Warn (msg string ) {
105104 if l .level .Enabled (zap .WarnLevel ) {
106- if ! l .shouldIgnore (msg ) {
105+ if ! l .ignoredPrefixes . Match (msg ) {
107106 l .init ()
108107 l .logger .Warnw (msg , nil )
109108 }
@@ -113,7 +112,7 @@ func (l *zapLogAdapter) Warn(msg string) {
113112func (l * zapLogAdapter ) Warnf (format string , args ... interface {}) {
114113 if l .level .Enabled (zap .WarnLevel ) {
115114 msg := fmt .Sprintf (format , args ... )
116- if ! l .shouldIgnore (msg ) {
115+ if ! l .ignoredPrefixes . Match (msg ) {
117116 l .init ()
118117 l .logger .Warnw (msg , nil )
119118 }
@@ -122,7 +121,7 @@ func (l *zapLogAdapter) Warnf(format string, args ...interface{}) {
122121
123122func (l * zapLogAdapter ) Error (msg string ) {
124123 if l .level .Enabled (zap .ErrorLevel ) {
125- if ! l .shouldIgnore (msg ) {
124+ if ! l .ignoredPrefixes . Match (msg ) {
126125 l .init ()
127126 l .logger .Errorw (msg , nil )
128127 }
@@ -132,18 +131,9 @@ func (l *zapLogAdapter) Error(msg string) {
132131func (l * zapLogAdapter ) Errorf (format string , args ... interface {}) {
133132 if l .level .Enabled (zap .ErrorLevel ) {
134133 msg := fmt .Sprintf (format , args ... )
135- if ! l .shouldIgnore (msg ) {
134+ if ! l .ignoredPrefixes . Match (msg ) {
136135 l .init ()
137136 l .logger .Errorw (msg , nil )
138137 }
139138 }
140139}
141-
142- func (l * zapLogAdapter ) shouldIgnore (msg string ) bool {
143- for _ , prefix := range l .ignoredPrefixes {
144- if strings .HasPrefix (msg , prefix ) {
145- return true
146- }
147- }
148- return false
149- }
0 commit comments