From 8c7078908b05357e199af4ee85fd2170d6dbdf8d Mon Sep 17 00:00:00 2001 From: Jeff Carr Date: Sat, 16 Aug 2025 16:24:47 -0500 Subject: [PATCH] more compat for 'fmt' package --- error.go | 6 ++++++ flags.go | 2 +- reallog.go | 11 +++++------ sscan.go | 10 ++++++++++ 4 files changed, 22 insertions(+), 7 deletions(-) create mode 100644 sscan.go diff --git a/error.go b/error.go index c1544d3..b1cfb78 100644 --- a/error.go +++ b/error.go @@ -4,6 +4,8 @@ package log +import "fmt" + func Error(err error, a ...any) { if ERROR.Disabled() { return @@ -11,3 +13,7 @@ func Error(err error, a ...any) { realPrintln("Error:", err) realPrintln(a...) } + +func Errorf(f string, a ...any) error { + return fmt.Errorf(f, a...) +} diff --git a/flags.go b/flags.go index 78d8b5e..1a179a3 100644 --- a/flags.go +++ b/flags.go @@ -148,7 +148,7 @@ func (f *LogFlag) Disabled() bool { if !f.Ok() { return true } - return ! f.b + return !f.b } // just the opposite of Disabled() diff --git a/reallog.go b/reallog.go index 249a03f..37a290a 100644 --- a/reallog.go +++ b/reallog.go @@ -19,7 +19,6 @@ func Timestamps(b bool) { timestamps = b } - var captureMode io.Writer func CaptureMode(w io.Writer) { @@ -64,11 +63,11 @@ func realPrintln(a ...any) { } else { // put timestamps on each line if captureMode == nil { - if timestamps { - reallog.Println(a...) - } else { - fmt.Println(a...) - } + if timestamps { + reallog.Println(a...) + } else { + fmt.Println(a...) + } } else { // TODO: add datestamp fmt.Fprintln(captureMode, a...) diff --git a/sscan.go b/sscan.go new file mode 100644 index 0000000..9850c39 --- /dev/null +++ b/sscan.go @@ -0,0 +1,10 @@ +package log + +import "fmt" + +// func Sprint(a ...any) string { +// return realSprint(a...) + +func Sscanf(f string, thing string, a ...any) (int, error) { + return fmt.Sscanf(f, thing, a...) +}