From 007e2de369f9fc26da3237646de14f2af5052ee8 Mon Sep 17 00:00:00 2001 From: ewy Date: Fri, 22 May 2026 16:54:49 +0200 Subject: initial commit --- spool/spool.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 spool/spool.go (limited to 'spool/spool.go') diff --git a/spool/spool.go b/spool/spool.go new file mode 100644 index 0000000..dcaf0e8 --- /dev/null +++ b/spool/spool.go @@ -0,0 +1,39 @@ +package spool + +import ( + "fmt" + "github.com/spf13/pflag" + "os" + "runtime/debug" + "time" +) + +var ( + DebugFlag = pflag.BoolP("debug", "d", false, "show debug output") +) + +func Debug(format string, args ...any) { + if !*DebugFlag { + return + } + _, _ = fmt.Fprintf(os.Stderr, format, args...) +} + +func Info(format string, args ...any) { + _, _ = fmt.Fprintf(os.Stdout, timestamp(format), args...) +} + +func Warn(format string, args ...any) { + _, _ = fmt.Fprintf(os.Stderr, timestamp(format), args...) +} + +func Panic(format string, args ...any) { + _, _ = fmt.Fprintf(os.Stderr, timestamp(format), args...) + debug.PrintStack() + os.Exit(1) +} + +func timestamp(in string) string { + n := time.Now() + return fmt.Sprintf("[%v] %v", n.Format(time.TimeOnly), in) +} -- cgit v1.3.1