Skip to content

Commit 79e2fa8

Browse files
authored
Merge pull request #1167 from skrashevich/feat-logging-to-file
feat(logging): add file output option for logging configuration
2 parents 1ab05e5 + 2ad0ded commit 79e2fa8

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

internal/app/log.go

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package app
33
import (
44
"io"
55
"os"
6+
"strings"
67

78
"github.com/mattn/go-isatty"
89
"github.com/rs/zerolog"
@@ -38,11 +39,17 @@ func initLogger() {
3839

3940
var writer io.Writer
4041

41-
switch modules["output"] {
42+
switch output, path, _ := strings.Cut(modules["output"], ":"); output {
4243
case "stderr":
4344
writer = os.Stderr
4445
case "stdout":
4546
writer = os.Stdout
47+
case "file":
48+
if path == "" {
49+
path = "go2rtc.log"
50+
}
51+
// if fail - only MemoryLog will be available
52+
writer, _ = os.OpenFile(path, os.O_APPEND|os.O_CREATE|os.O_WRONLY, 0644)
4653
}
4754

4855
timeFormat := modules["time"]

0 commit comments

Comments
 (0)