-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Expand file tree
/
Copy pathlogger.go
More file actions
91 lines (71 loc) · 2.34 KB
/
logger.go
File metadata and controls
91 lines (71 loc) · 2.34 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package libp2pwebrtc
import (
"context"
"fmt"
"log/slog"
logging "github.com/libp2p/go-libp2p/gologshim"
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 adapts pion's logger to go-libp2p's semantics.
// Pion logs routine connection events (client disconnects, protocol mismatches,
// state races) as ERROR/WARN, but these are normal operational noise from a
// service perspective. We downgrade all pion logs to DEBUG to prevent log spam
// while preserving debuggability when needed.
type pionLogger struct {
*slog.Logger
}
var pLog = pionLogger{pionLog}
var _ pionLogging.LeveledLogger = pLog
func (l pionLogger) Debug(s string) {
l.Logger.Debug(s)
}
func (l pionLogger) Debugf(s string, args ...interface{}) {
if l.Logger.Enabled(context.Background(), slog.LevelDebug) {
l.Logger.Debug(fmt.Sprintf(s, args...))
}
}
func (l pionLogger) Error(s string) {
l.Logger.Debug(s)
}
func (l pionLogger) Errorf(s string, args ...interface{}) {
if l.Logger.Enabled(context.Background(), slog.LevelDebug) {
l.Logger.Debug(fmt.Sprintf(s, args...))
}
}
func (l pionLogger) Info(s string) {
l.Logger.Debug(s)
}
func (l pionLogger) Infof(s string, args ...interface{}) {
if l.Logger.Enabled(context.Background(), slog.LevelDebug) {
l.Logger.Debug(fmt.Sprintf(s, args...))
}
}
func (l pionLogger) Warn(s string) {
l.Logger.Debug(s)
}
func (l pionLogger) Warnf(s string, args ...interface{}) {
if l.Logger.Enabled(context.Background(), slog.LevelDebug) {
l.Logger.Debug(fmt.Sprintf(s, args...))
}
}
func (l pionLogger) Trace(s string) {
l.Logger.Debug(s)
}
func (l pionLogger) Tracef(s string, args ...interface{}) {
if l.Logger.Enabled(context.Background(), slog.LevelDebug) {
l.Logger.Debug(fmt.Sprintf(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 unnecessarily. To avoid the allocations we use a single log
// object for all of pion logging.
func (loggerFactory) NewLogger(_ string) pionLogging.LeveledLogger {
return pLog
}
var _ pionLogging.LoggerFactory = loggerFactory{}
var pionLoggerFactory = loggerFactory{}