glow/log.go
Carlos Alexandro Becker fce3edf7db
feat!: cleanup and updated (#619)
* feat!: cleanup

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

* more cleanup

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

* fix: more cleanup

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

* fix: more cleanup

---------

Signed-off-by: Carlos Alexandro Becker <caarlos0@users.noreply.github.com>
2024-07-03 12:11:29 -03:00

27 lines
491 B
Go

package main
import (
"os"
"github.com/adrg/xdg"
"github.com/charmbracelet/log"
)
func getLogFilePath() (string, error) {
return xdg.CacheFile("glow/glow.log")
}
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
}