glow/log.go
Carlos Alexandro Becker fe066f2140
feat: allow config from CHARM_CONFIG_HOME and XDG_CONFIG_HOME (#621)
* feat: allow config from CHARM_CONFIG_HOME

closes #594
closes #495
closes #328
closes #475

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

* fix: improvements on config handling

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

* chore: log

---------

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
2024-07-08 22:33:49 -03:00

32 lines
620 B
Go

package main
import (
"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 to file, if set
logFile, err := getLogFilePath()
if err != 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.SetOutput(f)
log.SetLevel(log.DebugLevel)
return f.Close, nil
}