feat: log files to user directory
continuous-integration/drone/pr Build is failing Details
continuous-integration/drone/push Build is failing Details

This commit is contained in:
decentral1se 2023-12-29 19:04:45 +01:00
parent e4ce9b6552
commit 25229f1ea8
Signed by: decentral1se
GPG Key ID: 03789458B3D0C410
2 changed files with 24 additions and 13 deletions

View File

@ -7,6 +7,7 @@ import (
"os"
"os/exec"
"os/user"
"path"
"d1.hackers.moe/cairde/ui"
@ -75,28 +76,37 @@ func main() {
os.Exit(0)
}
// NOTE(d1): pending https://git.coopcloud.tech/decentral1se/cairde/issues/1
_, err := exec.LookPath("tor")
// NOTE(d1): pending https://git.coopcloud.tech/decentral1se/cairde/issues/1
if err != nil {
log.Fatal("main: could not find 'tor' command, is it installed?")
}
f, err := tea.LogToFile("cairde.log", "debug") // TODO
if err != nil {
log.Fatal(err)
}
defer f.Close()
filelogger, err := openPrivacyLog.NewFile(openPrivacyLog.LevelInfo, "cwtch.log") // TODO
if err == nil {
openPrivacyLog.SetStd(filelogger)
}
user, err := user.Current()
if err != nil {
log.Fatalf("main: unable to determine current user: %s", err)
}
userDir := path.Join(user.HomeDir, "/.cairde/")
if err := os.Mkdir(userDir, 0764); err != nil {
if !os.IsExist(err) {
log.Fatalf("main: unable to create user directory: %s", err)
}
}
cairdeLogPath := path.Join(userDir, "cairde.log")
f, err := tea.LogToFile(cairdeLogPath, "debug")
if err != nil {
log.Fatal(err)
}
defer f.Close()
cwtchLogPath := path.Join(userDir, "cwtch.log")
filelogger, err := openPrivacyLog.NewFile(openPrivacyLog.LevelInfo, cwtchLogPath)
if err == nil {
openPrivacyLog.SetStd(filelogger)
}
p := tea.NewProgram(
ui.NewModel(
user.Username,

View File

@ -17,7 +17,8 @@ ci:
@golangci-lint run ./...
clean:
@find -type f -name "*.log" -exec rm '{}' \;
@go clean && \
find ~/.cairde -type f -name "*.log" -exec rm '{}' \;
build: clean
@go build -ldflags=$(DIST_LDFLAGS) ./cmd/cairde