mirror of
https://github.com/charmbracelet/glow
synced 2024-11-10 06:04:18 +00:00
fix: handle not being able to create log file
This commit is contained in:
parent
b80e8312f2
commit
a1a85636ea
1 changed files with 4 additions and 7 deletions
7
log.go
7
log.go
|
@ -1,7 +1,6 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"os"
|
||||
"path/filepath"
|
||||
|
||||
|
@ -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
|
||||
}
|
||||
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)
|
||||
|
|
Loading…
Reference in a new issue