Skip to content

Commit

Permalink
fix: handle not being able to create log file
Browse files Browse the repository at this point in the history
  • Loading branch information
caarlos0 committed Jul 10, 2024
1 parent b80e831 commit a1a8563
Showing 1 changed file with 4 additions and 7 deletions.
11 changes: 4 additions & 7 deletions log.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package main

import (
"errors"
"os"
"path/filepath"

Expand All @@ -24,15 +23,13 @@ func setupLog() (func() error, error) {
return nil, err
}
if err := os.MkdirAll(filepath.Dir(logFile), 0o644); err != nil {
if errors.Is(err, os.ErrPermission) {
// log disabled
return nil, nil
}
return nil, err
// log disabled
return nil, nil
}
f, err := os.OpenFile(logFile, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0o644)
if err != nil {
return nil, err
// log disabled
return nil, nil
}
log.SetOutput(f)
log.SetLevel(log.DebugLevel)
Expand Down

0 comments on commit a1a8563

Please sign in to comment.