Skip to content
Merged
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
18 changes: 14 additions & 4 deletions pkg/unpackerr/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -153,20 +153,30 @@ func (u *Unpackerr) setupLogging() {
}

if u.Config.LogFile != "" {
u.rotatorr = rotatorr.NewMust(rotate)
var err error

u.rotatorr, err = rotatorr.New(rotate)
if err != nil {
// Fall back to stdout so we don't hammer the filesystem with failed open attempts.
u.rotatorr = nil
_, _ = os.Stdout.WriteString("[Unpackerr] Log file unavailable (check path and permissions!!), " +
"logging to stdout only: " + err.Error() + "\n")
}
}

stderr := os.Stdout
if u.ErrorStdErr {
stderr = os.Stderr
}

useLogFile := u.Config.LogFile != "" && u.rotatorr != nil

switch { // only use MultiWriter if we have > 1 writer.
case !u.Config.Quiet && u.Config.LogFile != "":
case !u.Config.Quiet && useLogFile:
u.updateLogOutput(io.MultiWriter(u.rotatorr, os.Stdout), io.MultiWriter(u.rotatorr, stderr))
case !u.Config.Quiet && u.Config.LogFile == "":
case !u.Config.Quiet && !useLogFile:
u.updateLogOutput(os.Stdout, stderr)
case u.Config.LogFile == "":
case !useLogFile:
u.updateLogOutput(io.Discard, io.Discard) // default is "nothing"
default:
u.updateLogOutput(u.rotatorr, u.rotatorr)
Expand Down
Loading