summaryrefslogtreecommitdiff
path: root/spool/spool.go
blob: dcaf0e8934361f7e252cadeaea6d5c1db3e268ca (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
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)
}