add SPEW as a logFlag type

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2023-12-31 19:44:55 -06:00
parent dd09a7c3ab
commit 9f53c74766
2 changed files with 41 additions and 8 deletions

View File

@ -9,12 +9,29 @@ var WARN bool = true
var ERROR bool = true var ERROR bool = true
var VERBOSE bool = false var VERBOSE bool = false
var SPEW bool = false // var SPEW bool = false
var SPEW logFlag
type logFlag struct {
b bool
name string
pkg string
desc string
}
var registered map[string][]string var registered map[string][]string
func init() { func init() {
registered = make(map[string][]string) registered = make(map[string][]string)
SPEW.b = false
SPEW.name = "SPEW"
SPEW.pkg = "log"
SPEW.desc = "Enable log.Spew()"
// register the default flags used by this log package
registered["log"] = []string{"SPEW","INFO", "WARN", "ERROR", "VERBOSE"}
} }
func All(b bool) { func All(b bool) {
@ -25,8 +42,7 @@ func All(b bool) {
Set("VERBOSE", b) Set("VERBOSE", b)
} }
func ListAll() map[string][]string { func ListFlags() map[string][]string {
registered["all"] = []string{"SPEW","INFO", "WARN", "ERROR", "VERBOSE"}
return registered return registered
} }
@ -37,7 +53,7 @@ func Set(flag string, b bool) {
case "WARN": case "WARN":
WARN = b WARN = b
case "SPEW": case "SPEW":
SPEW = b SPEW.b = b
case "ERROR": case "ERROR":
ERROR = b ERROR = b
case "VERBOSE": case "VERBOSE":
@ -54,7 +70,7 @@ func Get(flag string) bool {
case "WARN": case "WARN":
return WARN return WARN
case "SPEW": case "SPEW":
return SPEW return SPEW.b
case "ERROR": case "ERROR":
return ERROR return ERROR
case "VERBOSE": case "VERBOSE":

23
spew.go
View File

@ -5,10 +5,27 @@ import (
"github.com/davecgh/go-spew/spew" "github.com/davecgh/go-spew/spew"
) )
func Spew(a ...any) { func Spew(b any, a ...any) {
if ! SPEW { return } if ! SPEW.b { return }
origlog.Println("SPEW:", spew.Sdump(a...))
switch b.(type) {
case bool:
if ! b.(bool) {
return
}
origlog.Println("SPEW:", spew.Sdump(a...))
case logFlag:
var f logFlag
f = b.(logFlag)
if ! f.b {
return
}
origlog.Println("SPEW:", spew.Sdump(a...))
default:
origlog.Println("SPEW b:", spew.Sdump(b))
origlog.Println("SPEW a:", spew.Sdump(a...))
}
// origlog.Println("SPEW:", spew.Sdump(a...))
/* /*
scs := spew.ConfigState{Indent: "\t", MaxDepth: 1} scs := spew.ConfigState{Indent: "\t", MaxDepth: 1}
// Output using the ConfigState instance. // Output using the ConfigState instance.