Skip to content

Commit b166816

Browse files
authored
fix log print by config (#165)
1 parent ee84d5a commit b166816

5 files changed

Lines changed: 15 additions & 6 deletions

File tree

cmd/server/grpc/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,7 @@ func main() {
109109
os.Exit(-1)
110110
}
111111

112-
log.Init(conf.Log.Level)
112+
log.Init(conf.Log.Level, conf.Log.Fix)
113113

114114
log.Infof("--- Starting SFU Node ---")
115115
lis, err := net.Listen("tcp", addr)

cmd/server/json-rpc/main.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -371,6 +371,7 @@ func main() {
371371
showHelp()
372372
os.Exit(-1)
373373
}
374+
log.Init(conf.Log.Level, conf.Log.Fix)
374375

375376
log.Infof("--- Starting SFU Node ---")
376377
rpc := NewRPC()

config.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,4 @@ maxbuffertime = 1000
3333
[log]
3434
stats = true
3535
level = "debug"
36+
fix = ["proc.go", "asm_amd64.s", "jsonrpc2.go"]

pkg/log/log.go

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,14 @@ const (
2222

2323
// Config defines parameters for the logger
2424
type Config struct {
25-
Level string `mapstructure:"level"`
26-
Stats bool `mapstructure:"stats"`
25+
Level string `mapstructure:"level"`
26+
Stats bool `mapstructure:"stats"`
27+
Fix []string `mapstructure:"fix"`
2728
}
2829

2930
// Init initializes the package logger.
3031
// Supported levels are: ["debug", "info", "warn", "error"]
31-
func Init(level string) {
32+
func Init(level string, fix []string) {
3233
l := zerolog.GlobalLevel()
3334
switch level {
3435
case "trace":
@@ -53,7 +54,13 @@ func Init(level string) {
5354
output.FormatMessage = func(i interface{}) string {
5455
caller, file, line, _ := runtime.Caller(9)
5556
fileName := filepath.Base(file)
56-
if fileName == "asm_amd64.s" || fileName == "proc.go" {
57+
var needfix bool
58+
for _, b := range fix {
59+
if strings.Contains(fileName, b) {
60+
needfix = true
61+
}
62+
}
63+
if needfix {
5764
caller, file, line, _ = runtime.Caller(8)
5865
fileName = filepath.Base(file)
5966
}

pkg/sfu.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ func NewSFU(c Config) *SFU {
5757
receiver: c.Receiver,
5858
}
5959

60-
log.Init(c.Log.Level)
60+
log.Init(c.Log.Level, c.Log.Fix)
6161

6262
var icePortStart, icePortEnd uint16
6363

0 commit comments

Comments
 (0)