Skip to content
Merged
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
4 changes: 3 additions & 1 deletion examples/unpackerr.conf.example
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ log_queues = "1m"
## Write messages to a log file. This is the same data that is normally output to stdout.
## This setting is great for Docker users that want to export their logs to a file.
## The alternative is to use syslog to log the output of the application to a file.
## Default is no log file; this is unset. log_files=0 turns off auto-rotation.
## Default is no log file; this is unset.
## Except on macOS and Windows, the log file gets set to "~/.unpackerr/unpackerr.log"
## log_files=0 turns off auto-rotation.
## Default files is 10 and size(mb) is 10 Megabytes; both doubled if debug is true.
#log_file = '/downloads/unpackerr.log'
log_files = 10
Expand Down
30 changes: 14 additions & 16 deletions pkg/unpackerr/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,12 @@ func (u *Unpackerr) setupLogging() {
u.Logger.Error.SetFlags(log.Lshortfile | log.Lmicroseconds | log.Ldate)
}

logFile, err := homedir.Expand(u.Config.LogFile)
if err != nil {
logFile = u.Config.LogFile
if logFile, err := homedir.Expand(u.Config.LogFile); err == nil {
u.Config.LogFile = logFile
}

rotate := &rotatorr.Config{
Filepath: logFile, // log file name.
Filepath: u.Config.LogFile, // log file name.
FileSize: int64(u.Config.LogFileMb) * megabyte, // megabytes
Rotatorr: &timerotator.Layout{
FileCount: u.Config.LogFiles,
Expand All @@ -146,7 +145,7 @@ func (u *Unpackerr) setupLogging() {
DirMode: logsDirMode,
}

if logFile != "" {
if u.Config.LogFile != "" {
u.rotatorr = rotatorr.NewMust(rotate)
}

Expand All @@ -156,11 +155,11 @@ func (u *Unpackerr) setupLogging() {
}

switch { // only use MultiWriter if we have > 1 writer.
case !u.Config.Quiet && logFile != "":
case !u.Config.Quiet && u.Config.LogFile != "":
u.updateLogOutput(io.MultiWriter(u.rotatorr, os.Stdout), io.MultiWriter(u.rotatorr, stderr))
case !u.Config.Quiet && logFile == "":
case !u.Config.Quiet && u.Config.LogFile == "":
u.updateLogOutput(os.Stdout, stderr)
case logFile == "":
case u.Config.LogFile == "":
u.updateLogOutput(io.Discard, io.Discard) // default is "nothing"
default:
u.updateLogOutput(u.rotatorr, u.rotatorr)
Expand All @@ -185,26 +184,25 @@ func (u *Unpackerr) updateLogOutput(writer io.Writer, errors io.Writer) {
}

func (u *Unpackerr) setupHTTPLogging() {
logFile, err := homedir.Expand(u.Webserver.LogFile)
if err != nil {
logFile = u.Webserver.LogFile
if logFile, err := homedir.Expand(u.Webserver.LogFile); err == nil {
u.Webserver.LogFile = logFile
}

rotate := &rotatorr.Config{
Filepath: logFile, // log file name.
Filepath: u.Webserver.LogFile, // log file name.
FileSize: int64(u.Webserver.LogFileMb) * megabyte, // megabytes
Rotatorr: &timerotator.Layout{FileCount: u.Webserver.LogFiles},
DirMode: logsDirMode,
}

switch { // only use MultiWriter if we have > 1 writer.
case !u.Config.Quiet && logFile != "":
case !u.Config.Quiet && u.Webserver.LogFile != "":
u.Logger.HTTP.SetOutput(io.MultiWriter(rotatorr.NewMust(rotate), os.Stdout))
case !u.Config.Quiet && logFile == "":
case !u.Config.Quiet && u.Webserver.LogFile == "":
u.Logger.HTTP.SetOutput(os.Stdout)
case u.Config.Quiet && logFile == "":
case u.Config.Quiet && u.Webserver.LogFile == "":
u.Logger.HTTP.SetOutput(io.Discard)
default: // u.Config.Quiet && logFile != ""
default: // u.Config.Quiet && u.Webserver.LogFile != ""
u.Logger.HTTP.SetOutput(rotatorr.NewMust(rotate))
}
}
Expand Down