-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
webrtc: use a common logger for all pion logging
Internally pion uses a lot of logger objects. It's better to just share one logger across everything.
- Loading branch information
Showing
4 changed files
with
63 additions
and
28 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package libp2pwebrtc | ||
|
||
import ( | ||
logging "github.com/ipfs/go-log/v2" | ||
pionLogging "github.com/pion/logging" | ||
) | ||
|
||
var log = logging.Logger("webrtc-transport") | ||
|
||
// pionLog is the logger provided to pion for internal logging | ||
var pionLog = logging.Logger("webrtc-transport-pion") | ||
|
||
// pionLogger wraps the StandardLogger interface to provide a LeveledLogger interface | ||
// as expected by pion | ||
type pionLogger struct { | ||
logging.StandardLogger | ||
} | ||
|
||
var pLog = pionLogger{pionLog} | ||
|
||
var _ pionLogging.LeveledLogger = pLog | ||
|
||
func (l pionLogger) Debug(s string) { | ||
l.StandardLogger.Debug(s) | ||
} | ||
|
||
func (l pionLogger) Error(s string) { | ||
l.StandardLogger.Error(s) | ||
} | ||
|
||
func (l pionLogger) Info(s string) { | ||
l.StandardLogger.Info(s) | ||
} | ||
func (l pionLogger) Warn(s string) { | ||
l.StandardLogger.Warn(s) | ||
} | ||
|
||
func (l pionLogger) Trace(s string) { | ||
l.StandardLogger.Debug(s) | ||
} | ||
|
||
func (l pionLogger) Tracef(s string, args ...interface{}) { | ||
l.StandardLogger.Debugf(s, args) | ||
} | ||
|
||
// loggerFactory returns pLog for all new logger instances | ||
type loggerFactory struct{} | ||
|
||
// NewLogger returns pLog for all new logger instances. Internally pion creates lots of | ||
// separate logging objects like 1 separate logger per datachannel. To avoid this we | ||
// use a single log object for all of pion logging. | ||
func (loggerFactory) NewLogger(scope string) pionLogging.LeveledLogger { | ||
return pLog | ||
} | ||
|
||
var _ pionLogging.LoggerFactory = loggerFactory{} | ||
|
||
var pionLoggerFactory = loggerFactory{} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters