glow/log.go
Carlos Alexandro Becker c89c8bd6e7
feat: update glamour (#634)
* feat: updating glamour

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

* fix: trim space

* chore: bump

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

* chore(deps): bump

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>

* fix: perms

* fix: improve logs

* feat: update glamour

---------

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
2024-08-21 14:43:05 -03:00

39 lines
825 B
Go

package main
import (
"io"
"os"
"path/filepath"
"github.com/charmbracelet/log"
gap "github.com/muesli/go-app-paths"
)
func getLogFilePath() (string, error) {
dir, err := gap.NewScope(gap.User, "glow").CacheDir()
if err != nil {
return "", err
}
return filepath.Join(dir, "glow.log"), nil
}
func setupLog() (func() error, error) {
log.SetOutput(io.Discard)
// Log to file, if set
logFile, err := getLogFilePath()
if err != nil {
return nil, err
}
if err := os.MkdirAll(filepath.Dir(logFile), 0o755); err != nil {
// log disabled
return func() error { return nil }, nil
}
f, err := os.OpenFile(logFile, os.O_WRONLY|os.O_CREATE|os.O_APPEND, 0o644)
if err != nil {
// log disabled
return func() error { return nil }, nil
}
log.SetOutput(f)
log.SetLevel(log.DebugLevel)
return f.Close, nil
}