Skip to content

Commit

Permalink
refactor: improve logging format and consistency
Browse files Browse the repository at this point in the history
  • Loading branch information
revelaction committed Sep 19, 2024
1 parent 4d5100f commit 82814a0
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 11 deletions.
15 changes: 8 additions & 7 deletions cmd/ical-git/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -96,15 +96,16 @@ func main() {
cancel()
slog.Info("🔧 stop previous timers")
scheduler.StopTimers()
slog.Info("🔧 Reinizializing")
ctx, cancel, scheduler = initialize(configPath)

case os.Interrupt:
slog.Info("Interrupt called")
slog.Info("🔧 Interrupt called. Cancelling goroutines. Exiting")
cancel()
os.Exit(1)
}
case <-ctx.Done():
slog.Error("🔧🚨 Tick Error. Context cancelled")
slog.Error("🚨 Tick Error. Context was cancelled. Reinizializing")
scheduler.StopTimers()
ctx, cancel, scheduler = initialize(configPath)
}
Expand Down Expand Up @@ -200,14 +201,14 @@ func run(conf config.Config, sc *schedule.Scheduler) error {
slog.Info("🚀 starting run")

tickStart := time.Now()
slog.Info("⏰ Tick start time", "start", tickStart.Format(time.RFC3339))
slog.Info("⏰ Tick start time", "start", tickStart.Format("2006-01-02 15:04:05 MST"))

var f fetch.Fetcher
if conf.IsFetcherGit() {
slog.Info("🧲 Fetch: git")
slog.Info("🧲 Fetch: git")
f = git.New(conf.FetcherGit.Url, conf.FetcherGit.PrivateKeyPath)
} else {
slog.Info("🧲 Fetch: filesystem")
slog.Info("🧲 Fetch: filesystem")
f = filesystem.New(conf.FetcherFilesystem.Directory)
}

Expand All @@ -216,12 +217,12 @@ func run(conf config.Config, sc *schedule.Scheduler) error {
p := ical.NewParser(conf, tickStart)
for f := range ch {
if f.Error != nil {
slog.Error("🧲 Fetch:", "🚨 Error:", f.Error)
slog.Error("🧲 Fetch:", "🚨 Error:", f.Error)
return fmt.Errorf("error: %w", f.Error)
}
err := p.Parse(f)
if err != nil {
slog.Info("👀 Parse: error. Skipping", "error", err)
slog.Info("👀 Parse: error. Skipping", "error", err)
}
}

Expand Down
6 changes: 3 additions & 3 deletions ical/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,18 @@ func (p *Parser) Parse(f fetch.File) error {

eventTime, err := et.nextTime(p.start)
if err != nil {
slog.Error("📅 Event", "📁", filepath.Base(f.Path), "📌", eventTime, "🚨", err)
slog.Error("📅 Event", "📁", filepath.Base(f.Path), "📌", eventTime.Format("2006-01-02 15:04:05 MST"), "🚨", err)
continue
}

// expired event
if eventTime.IsZero() {
slog.Info("📅 Event", "📁", filepath.Base(f.Path), "📌", eventTime, "💀️", "expired")
slog.Info("📅 Event", "📁", filepath.Base(f.Path), "📌", eventTime.Format("2006-01-02 15:04:05 MST"), "💀️", "expired")
continue
}

in := eventTime.Sub(p.start).Truncate(1 * time.Second)
slog.Info("📅 Event", "📁", filepath.Base(f.Path), "📌", eventTime, "🔖", in)
slog.Info("📅 Event", "📁", filepath.Base(f.Path), "📌", eventTime.Format("2006-01-02 15:04:05 MST"), "🔖", in)

// Event Alarms
for _, a := range getEventAlarms(event, p.conf.NotifierTypes) {
Expand Down
2 changes: 1 addition & 1 deletion notify/schedule/schedule.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ func (s *Scheduler) Schedule(notifications []notify.Notification, tickStart time
for _, n := range notifications {

dur := n.Time.Sub(tickStart)
slog.Info("🚦 Schedule 🔔", "📁", filepath.Base(n.EventPath), "📌", n.Time, "🔖", dur.Truncate(1*time.Second), "durIso", n.DurIso8601, "type", n.Type, "source", n.Source)
slog.Info("🚦 Schedule 🔔", "📁", filepath.Base(n.EventPath), "📌", n.Time.Format("2006-01-02 15:04:05 MST"), "🔖", dur.Truncate(1*time.Second), "durIso", n.DurIso8601, "type", n.Type, "source", n.Source)
//dur = 3 * time.Second // Hack

f, err := s.getNotifyFunc(n)
Expand Down

0 comments on commit 82814a0

Please sign in to comment.