summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2025-09-06 15:23:22 -0500
committerJeff Carr <[email protected]>2025-09-06 15:23:22 -0500
commit854796ba7204e4f8e8c5b5ad01de354c8913214f (patch)
treee7e4f5d4892fddd60f0261e50e95284ae745798a
parent8c7078908b05357e199af4ee85fd2170d6dbdf8d (diff)
add On() & Off() also Fprintln() & Fprintf()HEADv0.25.1v0.25.0v0.22.18masterdevel
-rw-r--r--Makefile2
-rw-r--r--flags.go2
-rw-r--r--original.go10
-rw-r--r--reallog.go22
4 files changed, 35 insertions, 1 deletions
diff --git a/Makefile b/Makefile
index 97d7a42..ae01975 100644
--- a/Makefile
+++ b/Makefile
@@ -1,6 +1,6 @@
# git remote add github [email protected]:wit-go/log.git
-all: vet
+all: goimport vet
@#GO111MODULE=off go vet -x
@echo this go library builds ok
diff --git a/flags.go b/flags.go
index 1a179a3..94e2425 100644
--- a/flags.go
+++ b/flags.go
@@ -30,6 +30,8 @@ import (
"sync"
)
+var off bool // completely shut up until I tell you to talk again
+
var INFO *LogFlag // toggles log.Info()
var VERBOSE *LogFlag // toggles log.Verbose()
var SPEW *LogFlag // toggles log.Spew()
diff --git a/original.go b/original.go
index 7663e5e..e56aa2a 100644
--- a/original.go
+++ b/original.go
@@ -1,5 +1,7 @@
package log
+import "io"
+
/*
import (
"log"
@@ -81,6 +83,14 @@ func Sprintln(a ...any) string {
return realSprintln(a...)
}
+func Fprintln(w io.Writer, a ...any) (int, error) {
+ return realFprintln(w, a...)
+}
+
+func Fprintf(w io.Writer, s string, a ...any) (int, error) {
+ return realFprintf(w, s, a...)
+}
+
func Fatalln(a ...any) {
realFatalln(a...)
}
diff --git a/reallog.go b/reallog.go
index 37a290a..f44abdc 100644
--- a/reallog.go
+++ b/reallog.go
@@ -11,6 +11,14 @@ import (
"time"
)
+func Off() {
+ off = true
+}
+
+func On() {
+ off = false
+}
+
func DaemonMode(b bool) {
daemonMode = b
}
@@ -53,6 +61,9 @@ func DaemonShow() bool {
}
func realPrintln(a ...any) {
+ if off {
+ return
+ }
if daemonMode {
// in daemon mode, don't put timestamps on each line
if captureMode == nil {
@@ -88,6 +99,9 @@ func realPrintln(a ...any) {
}
func realPrintf(s string, a ...any) {
+ if off {
+ return
+ }
if daemonMode {
// in daemon mode, don't put timestamps on each line
if captureMode == nil {
@@ -133,6 +147,14 @@ func realSprintln(a ...any) string {
return fmt.Sprintln(a...)
}
+func realFprintln(w io.Writer, a ...any) (int, error) {
+ return fmt.Fprintln(w, a...)
+}
+
+func realFprintf(w io.Writer, s string, a ...any) (int, error) {
+ return fmt.Fprintf(w, s, a...)
+}
+
func realFatalln(a ...any) {
reallog.Fatalln(a...)
}