Skip to content

Commit

Permalink
Merge pull request #1167 from skrashevich/feat-logging-to-file
Browse files Browse the repository at this point in the history
feat(logging): add file output option for logging configuration
  • Loading branch information
AlexxIT authored Feb 24, 2025
2 parents 1ab05e5 + 2ad0ded commit 79e2fa8
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion internal/app/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package app
import (
"io"
"os"
"strings"

"github.com/mattn/go-isatty"
"github.com/rs/zerolog"
Expand Down Expand Up @@ -38,11 +39,17 @@ func initLogger() {

var writer io.Writer

switch modules["output"] {
switch output, path, _ := strings.Cut(modules["output"], ":"); output {
case "stderr":
writer = os.Stderr
case "stdout":
writer = os.Stdout
case "file":
if path == "" {
path = "go2rtc.log"
}
// if fail - only MemoryLog will be available
writer, _ = os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
}

timeFormat := modules["time"]
Expand Down

0 comments on commit 79e2fa8

Please sign in to comment.