half working 'daemon mode'
Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
parent
54c0947452
commit
2cf02ee2e5
8
error.go
8
error.go
|
@ -4,12 +4,8 @@
|
||||||
|
|
||||||
package log
|
package log
|
||||||
|
|
||||||
import (
|
|
||||||
origlog "log"
|
|
||||||
)
|
|
||||||
|
|
||||||
func Error(err error, a ...any) {
|
func Error(err error, a ...any) {
|
||||||
if ! ERROR.Get() { return }
|
if ! ERROR.Get() { return }
|
||||||
origlog.Println("Error:", err)
|
realPrintln("Error:", err)
|
||||||
origlog.Println(a...)
|
realPrintln(a...)
|
||||||
}
|
}
|
||||||
|
|
10
log.go
10
log.go
|
@ -4,10 +4,6 @@
|
||||||
|
|
||||||
package log
|
package log
|
||||||
|
|
||||||
import (
|
|
||||||
origlog "log"
|
|
||||||
)
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
||||||
a simple way turn logging messages on and off. The gui config
|
a simple way turn logging messages on and off. The gui config
|
||||||
|
@ -29,16 +25,16 @@ func Log(f *LogFlag, a ...any) {
|
||||||
if ! f.Ok() {
|
if ! f.Ok() {
|
||||||
// if the flag is NULL, notify the user they didn't initialize the flag
|
// if the flag is NULL, notify the user they didn't initialize the flag
|
||||||
a = append([]any{"FLAG = NULL"}, a...)
|
a = append([]any{"FLAG = NULL"}, a...)
|
||||||
origlog.Println(a...)
|
realPrintln(a...)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
if ! f.Get() { return }
|
if ! f.Get() { return }
|
||||||
a = append([]any{f.short}, a...)
|
a = append([]any{f.short}, a...)
|
||||||
origlog.Println(a...)
|
realPrintln(a...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Logf(f *LogFlag, s string, a ...any) {
|
func Logf(f *LogFlag, s string, a ...any) {
|
||||||
if ! f.Get() { return }
|
if ! f.Get() { return }
|
||||||
s = f.short + " " + s
|
s = f.short + " " + s
|
||||||
origlog.Printf(s, a...)
|
realPrintf(s, a...)
|
||||||
}
|
}
|
||||||
|
|
15
original.go
15
original.go
|
@ -49,31 +49,26 @@ package log
|
||||||
func (l *Logger) Writer() io.Writer
|
func (l *Logger) Writer() io.Writer
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
|
||||||
import (
|
|
||||||
origlog "log"
|
|
||||||
)
|
|
||||||
|
|
||||||
func Println(a ...any) {
|
func Println(a ...any) {
|
||||||
if ! PRINTLN.Ok() { return }
|
if ! PRINTLN.Ok() { return }
|
||||||
if ! PRINTLN.b { return }
|
if ! PRINTLN.b { return }
|
||||||
origlog.Println(a...)
|
realPrintln(a...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Printf(s string, a ...any) {
|
func Printf(s string, a ...any) {
|
||||||
if ! PRINTLN.Ok() { return }
|
if ! PRINTLN.Ok() { return }
|
||||||
if ! PRINTLN.b { return }
|
if ! PRINTLN.b { return }
|
||||||
origlog.Printf(s, a...)
|
realPrintf(s, a...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Fatalln(a ...any) {
|
func Fatalln(a ...any) {
|
||||||
origlog.Fatalln(a...)
|
realFatalln(a...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Fatalf(s string, a ...any) {
|
func Fatalf(s string, a ...any) {
|
||||||
origlog.Fatalf(s, a...)
|
realFatalf(s, a...)
|
||||||
}
|
}
|
||||||
|
|
||||||
func Fatal(s string, a ...any) {
|
func Fatal(s string, a ...any) {
|
||||||
origlog.Fatalf(s, a...)
|
realFatalf(s, a...)
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,43 @@
|
||||||
|
package log
|
||||||
|
|
||||||
|
// implements 'daemon' mode so switches to fmt
|
||||||
|
// instead of log so that timestamps are not printed twice
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
reallog "log"
|
||||||
|
)
|
||||||
|
|
||||||
|
var daemonMode bool = false
|
||||||
|
|
||||||
|
func DaemonMode(b bool) {
|
||||||
|
daemonMode = b
|
||||||
|
}
|
||||||
|
|
||||||
|
func realPrintln(a ...any) {
|
||||||
|
if daemonMode {
|
||||||
|
fmt.Println(a...)
|
||||||
|
} else {
|
||||||
|
reallog.Println(a...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func realPrintf(s string, a ...any) {
|
||||||
|
if daemonMode {
|
||||||
|
fmt.Printf(s, a...)
|
||||||
|
} else {
|
||||||
|
reallog.Printf(s, a...)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
func realFatalln(a ...any) {
|
||||||
|
reallog.Fatalln(a...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func realFatalf(s string, a ...any) {
|
||||||
|
reallog.Fatalf(s, a...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func realFatal(s string, a ...any) {
|
||||||
|
reallog.Fatalf(s, a...)
|
||||||
|
}
|
11
spew.go
11
spew.go
|
@ -5,7 +5,6 @@
|
||||||
package log
|
package log
|
||||||
|
|
||||||
import (
|
import (
|
||||||
origlog "log"
|
|
||||||
"go.wit.com/dev/davecgh/spew"
|
"go.wit.com/dev/davecgh/spew"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -18,19 +17,19 @@ func Spew(b any, a ...any) {
|
||||||
if ! b.(bool) {
|
if ! b.(bool) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
origlog.Println("SPEW:", spew.Sdump(a...))
|
realPrintln("SPEW:", spew.Sdump(a...))
|
||||||
case LogFlag:
|
case LogFlag:
|
||||||
var f LogFlag
|
var f LogFlag
|
||||||
f = b.(LogFlag)
|
f = b.(LogFlag)
|
||||||
if ! f.b {
|
if ! f.b {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
origlog.Println("SPEW:", spew.Sdump(a...))
|
realPrintln("SPEW:", spew.Sdump(a...))
|
||||||
default:
|
default:
|
||||||
origlog.Println("SPEW b:", spew.Sdump(b))
|
realPrintln("SPEW b:", spew.Sdump(b))
|
||||||
origlog.Println("SPEW a:", spew.Sdump(a...))
|
realPrintln("SPEW a:", spew.Sdump(a...))
|
||||||
}
|
}
|
||||||
// origlog.Println("SPEW:", spew.Sdump(a...))
|
// realPrintln("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.
|
||||||
|
|
Loading…
Reference in New Issue