Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(logging): add file output option for logging configuration #1167

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -1213,6 +1213,7 @@ log:
rtsp: warn
streams: error
webrtc: fatal
output: stdout # Available output options are: stdout, stderr, or a file path.
```

## Security
Expand Down
14 changes: 14 additions & 0 deletions internal/app/log.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"]
Expand Down