File tree Expand file tree Collapse file tree 1 file changed +14
-4
lines changed
Expand file tree Collapse file tree 1 file changed +14
-4
lines changed Original file line number Diff line number Diff line change @@ -153,20 +153,30 @@ func (u *Unpackerr) setupLogging() {
153153 }
154154
155155 if u .Config .LogFile != "" {
156- u .rotatorr = rotatorr .NewMust (rotate )
156+ var err error
157+
158+ u .rotatorr , err = rotatorr .New (rotate )
159+ if err != nil {
160+ // Fall back to stdout so we don't hammer the filesystem with failed open attempts.
161+ u .rotatorr = nil
162+ _ , _ = os .Stdout .WriteString ("[Unpackerr] Log file unavailable (check path and permissions!!), " +
163+ "logging to stdout only: " + err .Error () + "\n " )
164+ }
157165 }
158166
159167 stderr := os .Stdout
160168 if u .ErrorStdErr {
161169 stderr = os .Stderr
162170 }
163171
172+ useLogFile := u .Config .LogFile != "" && u .rotatorr != nil
173+
164174 switch { // only use MultiWriter if we have > 1 writer.
165- case ! u .Config .Quiet && u . Config . LogFile != "" :
175+ case ! u .Config .Quiet && useLogFile :
166176 u .updateLogOutput (io .MultiWriter (u .rotatorr , os .Stdout ), io .MultiWriter (u .rotatorr , stderr ))
167- case ! u .Config .Quiet && u . Config . LogFile == "" :
177+ case ! u .Config .Quiet && ! useLogFile :
168178 u .updateLogOutput (os .Stdout , stderr )
169- case u . Config . LogFile == "" :
179+ case ! useLogFile :
170180 u .updateLogOutput (io .Discard , io .Discard ) // default is "nothing"
171181 default :
172182 u .updateLogOutput (u .rotatorr , u .rotatorr )
You can’t perform that action at this time.
0 commit comments