Skip to content
This repository has been archived by the owner on Feb 3, 2023. It is now read-only.

Commit

Permalink
add timestamp for logger
Browse files Browse the repository at this point in the history
  • Loading branch information
ingbyr committed Sep 11, 2022
1 parent dd6d504 commit 5d2b1b1
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions log/tui.go → log/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package log
import (
tea "github.com/charmbracelet/bubbletea"
"os"
"time"
)

var logFile *os.File
Expand All @@ -13,18 +14,23 @@ func New(file string) error {
if err != nil {
return err
}
Debug("==============")
Debug(">>> Start logging at " + nowStr())
return nil
}

func Debug(msg string) {
if _, err := logFile.WriteString("[DEBUG] " + msg + "\n"); err != nil {
if _, err := logFile.WriteString("[DEBUG " + nowStr() + "] " + msg + "\n"); err != nil {
panic(err)
}
}

func Error(err error) {
if _, err := logFile.WriteString("[ERROR] " + err.Error()); err != nil {

if _, err := logFile.WriteString("[ERROR" + nowStr() + "] " + err.Error()); err != nil {
panic(err)
}
}

func nowStr() string {
return time.Now().Format(time.RFC3339)
}

0 comments on commit 5d2b1b1

Please sign in to comment.