Skip to content

Commit 9a2ec49

Browse files
Move media related logging utilities from egress to protocol (#990)
1 parent 715433b commit 9a2ec49

File tree

3 files changed

+104
-0
lines changed

3 files changed

+104
-0
lines changed

.changeset/chilly-years-obey.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"@livekit/protocol": patch
3+
---
4+
5+
Move media related logging utilities from egress to protocol

logger/medialogutils/cmd.go

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
// Copyright 2025 LiveKit, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package medialogutils
16+
17+
import (
18+
"fmt"
19+
"strings"
20+
21+
"github.com/livekit/protocol/logger"
22+
)
23+
24+
// CmdLogger logs cmd outputs
25+
type CmdLogger struct {
26+
name string
27+
}
28+
29+
func NewCmdLogger(name string) *CmdLogger {
30+
return &CmdLogger{
31+
name: name,
32+
}
33+
}
34+
35+
func (l *CmdLogger) Write(p []byte) (int, error) {
36+
logger.Infow(fmt.Sprintf("%s: %s", l.name, string(p)))
37+
return len(p), nil
38+
}
39+
40+
// HandlerLogger catches stray outputs from egress handlers
41+
type HandlerLogger struct {
42+
logger logger.Logger
43+
}
44+
45+
func NewHandlerLogger(keyAndValues ...any) *HandlerLogger {
46+
return &HandlerLogger{
47+
logger: logger.GetLogger().WithValues(keyAndValues...),
48+
}
49+
}
50+
51+
func (l *HandlerLogger) Write(p []byte) (n int, err error) {
52+
s := string(p)
53+
if strings.HasSuffix(s, "}\n") {
54+
// normal handler logs
55+
fmt.Print(s)
56+
} else if strings.HasPrefix(s, "0:00:") {
57+
// ignore cuda and template not mapped gstreamer warnings
58+
} else if strings.HasPrefix(s, "turnc") {
59+
// warn on turnc error
60+
l.logger.Infow(s, nil)
61+
} else {
62+
// panics and unexpected errors
63+
l.logger.Errorw(s, nil)
64+
}
65+
66+
return len(p), nil
67+
}

logger/medialogutils/override.go

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Copyright 2025 LiveKit, Inc.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
15+
package medialogutils
16+
17+
import "github.com/livekit/protocol/logger"
18+
19+
// OverrideLogger converts errors to warnings
20+
type OverrideLogger struct {
21+
logger.Logger
22+
}
23+
24+
func NewOverrideLogger() *OverrideLogger {
25+
return &OverrideLogger{
26+
Logger: logger.GetLogger(),
27+
}
28+
}
29+
30+
func (l *OverrideLogger) Errorw(msg string, err error, keysAndValues ...interface{}) {
31+
l.Logger.Warnw(msg, err, keysAndValues...)
32+
}

0 commit comments

Comments
 (0)