summaryrefslogtreecommitdiff
path: root/spool/spool.go
diff options
context:
space:
mode:
Diffstat (limited to 'spool/spool.go')
-rw-r--r--spool/spool.go39
1 files changed, 39 insertions, 0 deletions
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)
+}