diff --git a/README.md b/README.md index c31ed748..faabfa6b 100644 --- a/README.md +++ b/README.md @@ -1213,6 +1213,7 @@ log: rtsp: warn streams: error webrtc: fatal + output: stdout # Available output options are: stdout, stderr, or a file path. ``` ## Security diff --git a/internal/app/log.go b/internal/app/log.go index 222f6f2b..dd29ad06 100644 --- a/internal/app/log.go +++ b/internal/app/log.go @@ -24,6 +24,20 @@ func NewLogger(config map[string]string) zerolog.Logger { writer = os.Stderr case "stdout": writer = os.Stdout + case "file": + filePath := config["file"] + if filePath == "" { + filePath = "go2rtc.log" + } + file, err := os.OpenFile(filePath, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644) + if err != nil { + os.Stdout.WriteString("Error: Failed to open log file: " + err.Error() + ". Log output is set to stdout now.\n") + writer = os.Stdout + } else { + writer = file + } + default: + writer = os.Stdout } timeFormat := config["time"]