Skip to content

Commit

Permalink
♻️ Rewrite Fatal() Fatalf() Panic() Panicf()
Browse files Browse the repository at this point in the history
  • Loading branch information
0uep committed Oct 20, 2022
1 parent 8b79aa5 commit 605890c
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions emo.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package emo
import (
"fmt"
"log"
"os"
"runtime"
"strconv"
"strings"
Expand Down Expand Up @@ -441,13 +442,17 @@ func Fatalf(format string, v ...any) {

func (zone Zone) Fatal(args ...any) {
msg := zone.S().NewEvent("🤯", true, args...).Message()
log.Fatal(msg)
if timestampPrefixed {
log.Fatal(msg)
} else {
fmt.Println(msg)
os.Exit(1)
}
}

func (zone Zone) Fatalf(format string, v ...any) {
s := fmt.Sprintf(format, v...)
msg := zone.S().NewEvent("🤯", true, s).Message()
log.Fatal(msg)
zone.S(1).Fatal(s)
}

func Panic(args ...any) {
Expand All @@ -460,13 +465,16 @@ func Panicf(format string, v ...any) {

func (zone Zone) Panic(args ...any) {
msg := zone.S().NewEvent("😵", true, args...).Message()
log.Panic(msg)
if timestampPrefixed {
log.Panic(msg)
} else {
panic(msg)
}
}

func (zone Zone) Panicf(format string, v ...any) {
s := fmt.Sprintf(format, v...)
msg := zone.S().NewEvent("😵", true, s).Message()
log.Panic(msg)
zone.S(1).Panic(s)
}

// --- following functions colorize output depending on configuration ---
Expand Down

0 comments on commit 605890c

Please sign in to comment.