feat(logging): add file output option for logging configuration
This commit is contained in:
@@ -1213,6 +1213,7 @@ log:
|
|||||||
rtsp: warn
|
rtsp: warn
|
||||||
streams: error
|
streams: error
|
||||||
webrtc: fatal
|
webrtc: fatal
|
||||||
|
output: stdout # Available output options are: stdout, stderr, or a file path.
|
||||||
```
|
```
|
||||||
|
|
||||||
## Security
|
## Security
|
||||||
|
|||||||
@@ -24,6 +24,19 @@ func NewLogger(config map[string]string) zerolog.Logger {
|
|||||||
writer = os.Stderr
|
writer = os.Stderr
|
||||||
case "stdout":
|
case "stdout":
|
||||||
writer = os.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 {
|
||||||
|
log.Error().Msgf("failed to open log file %s: %v", filePath, err)
|
||||||
|
}
|
||||||
|
defer file.Close()
|
||||||
|
writer = file
|
||||||
|
default:
|
||||||
|
writer = os.Stdout
|
||||||
}
|
}
|
||||||
|
|
||||||
timeFormat := config["time"]
|
timeFormat := config["time"]
|
||||||
|
|||||||
Reference in New Issue
Block a user