mirror of
https://github.com/taigrr/wtf
synced 2025-01-18 04:03:14 -08:00
This allows us to use the logger from the wtf directory For example when trying to debug sort ordering in focus_tracker
40 lines
623 B
Go
40 lines
623 B
Go
package logger
|
|
|
|
import (
|
|
"log"
|
|
"os"
|
|
"path/filepath"
|
|
|
|
"github.com/wtfutil/wtf/utils"
|
|
)
|
|
|
|
/* -------------------- Exported Functions -------------------- */
|
|
|
|
func Log(msg string) {
|
|
if LogFileMissing() {
|
|
return
|
|
}
|
|
|
|
f, err := os.OpenFile(LogFilePath(), os.O_RDWR|os.O_CREATE|os.O_APPEND, 0600)
|
|
if err != nil {
|
|
log.Fatalf("error opening file: %v", err)
|
|
}
|
|
defer f.Close()
|
|
|
|
log.SetOutput(f)
|
|
log.Println(msg)
|
|
}
|
|
|
|
func LogFileMissing() bool {
|
|
return LogFilePath() == ""
|
|
}
|
|
|
|
func LogFilePath() string {
|
|
dir, err := utils.Home()
|
|
if err != nil {
|
|
return ""
|
|
}
|
|
|
|
return filepath.Join(dir, ".config", "wtf", "log.txt")
|
|
}
|