Skip to content

Commit 048be58

Browse files
committed
Add logger factory option
1 parent a8f8a9b commit 048be58

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

pkg/rtpfb/interceptor.go

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ type packetLog interface {
3939
// Option can be used to set initial options on CCFB interceptors.
4040
type Option func(*Interceptor) error
4141

42+
func WithLoggerFactory(lf logging.LoggerFactory) Option {
43+
return func(i *Interceptor) error {
44+
i.logFactory = lf
45+
46+
return nil
47+
}
48+
}
49+
4250
func timeFactory(f func() time.Time) Option {
4351
return func(i *Interceptor) error {
4452
i.timestamp = f
@@ -70,16 +78,18 @@ func NewInterceptor(opts ...Option) (*InterceptorFactory, error) {
7078
// NewInterceptor returns a new ccfb.Interceptor.
7179
func (f *InterceptorFactory) NewInterceptor(_ string) (interceptor.Interceptor, error) {
7280
in := &Interceptor{
73-
NoOp: interceptor.NoOp{},
74-
log: logging.NewDefaultLoggerFactory().NewLogger("ccfb_interceptor"),
75-
timestamp: time.Now,
76-
history: newHistory(),
81+
NoOp: interceptor.NoOp{},
82+
logFactory: logging.NewDefaultLoggerFactory(),
83+
log: nil,
84+
timestamp: time.Now,
85+
history: newHistory(),
7786
}
7887
for _, opt := range f.opts {
7988
if err := opt(in); err != nil {
8089
return nil, err
8190
}
8291
}
92+
in.log = in.logFactory.NewLogger("ccfb_interceptor")
8393

8494
return in, nil
8595
}
@@ -92,8 +102,9 @@ func (f *InterceptorFactory) NewInterceptor(_ string) (interceptor.Interceptor,
92102
// report, a PacketReport will be added to the ccfb.Report.
93103
type Interceptor struct {
94104
interceptor.NoOp
95-
log logging.LeveledLogger
96-
timestamp func() time.Time
105+
logFactory logging.LoggerFactory
106+
log logging.LeveledLogger
107+
timestamp func() time.Time
97108

98109
history packetLog
99110
}

0 commit comments

Comments
 (0)