Compare commits

...

2 Commits

Author SHA1 Message Date
Jeff Carr 854796ba72 add On() & Off() also Fprintln() & Fprintf() 2025-09-06 15:23:22 -05:00
Jeff Carr 8c7078908b more compat for 'fmt' package 2025-08-16 21:50:21 -05:00
6 changed files with 57 additions and 8 deletions

View File

@ -1,6 +1,6 @@
# git remote add github git@github.com:wit-go/log.git
all: vet
all: goimport vet
@#GO111MODULE=off go vet -x
@echo this go library builds ok

View File

@ -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...)
}

View File

@ -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()
@ -148,7 +150,7 @@ func (f *LogFlag) Disabled() bool {
if !f.Ok() {
return true
}
return ! f.b
return !f.b
}
// just the opposite of Disabled()

View File

@ -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...)
}

View File

@ -11,6 +11,14 @@ import (
"time"
)
func Off() {
off = true
}
func On() {
off = false
}
func DaemonMode(b bool) {
daemonMode = b
}
@ -19,7 +27,6 @@ func Timestamps(b bool) {
timestamps = b
}
var captureMode io.Writer
func CaptureMode(w io.Writer) {
@ -54,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 {
@ -89,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 {
@ -134,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...)
}

10
sscan.go Normal file
View File

@ -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...)
}