mirror of
https://github.com/AlexxIT/go2rtc.git
synced 2025-10-05 16:26:50 +08:00
Merge pull request #1167 from skrashevich/feat-logging-to-file
feat(logging): add file output option for logging configuration
This commit is contained in:
@@ -3,6 +3,7 @@ package app
|
|||||||
import (
|
import (
|
||||||
"io"
|
"io"
|
||||||
"os"
|
"os"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/mattn/go-isatty"
|
"github.com/mattn/go-isatty"
|
||||||
"github.com/rs/zerolog"
|
"github.com/rs/zerolog"
|
||||||
@@ -38,11 +39,17 @@ func initLogger() {
|
|||||||
|
|
||||||
var writer io.Writer
|
var writer io.Writer
|
||||||
|
|
||||||
switch modules["output"] {
|
switch output, path, _ := strings.Cut(modules["output"], ":"); output {
|
||||||
case "stderr":
|
case "stderr":
|
||||||
writer = os.Stderr
|
writer = os.Stderr
|
||||||
case "stdout":
|
case "stdout":
|
||||||
writer = os.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"]
|
timeFormat := modules["time"]
|
||||||
|
Reference in New Issue
Block a user