remove places it would exit()

Signed-off-by: Jeff Carr <jcarr@wit.com>
This commit is contained in:
Jeff Carr 2023-03-28 08:54:18 -05:00
parent 146249a13d
commit 080acc8f3c
3 changed files with 21 additions and 112 deletions

View File

@ -40,6 +40,5 @@ func Parse (p *arg.Parser) {
log.Println("dnssec.Parse", i, v) log.Println("dnssec.Parse", i, v)
} }
p.Jcarr() p.Jcarr()
exit()
} }
*/ */

View File

@ -137,14 +137,13 @@ func Dnstrace(hostname string, qtypestr string) []dns.RR {
r, rtt, err := c.RecursiveQuery(m, t) r, rtt, err := c.RecursiveQuery(m, t)
if err != nil { if err != nil {
log(args.VerboseDnssec, col("*** error: %v\n", cRed), err) log(args.VerboseDnssec, col("*** error: %v\n", cRed), err)
exit(1) return nil
} }
log(args.VerboseDnssec) log(args.VerboseDnssec)
log(args.VerboseDnssec, col(";; Cold best path time: %s\n\n", cGray), rtt) log(args.VerboseDnssec, col(";; Cold best path time: %s\n\n", cGray), rtt)
for i, rr := range r.Answer { for i, rr := range r.Answer {
log(args.VerboseDnssec, "r.Answer =", i, rr, args.VerboseDnssec) log(args.VerboseDnssec, "r.Answer =", i, rr, args.VerboseDnssec)
// exit(0)
} }
return r.Answer return r.Answer
// for _, rr := range r.Answer { // for _, rr := range r.Answer {

121
log.go
View File

@ -1,119 +1,30 @@
//
// version v1.1
//
// I like things to be easy.
//
// this means all the log settings are in one place. it should allow
// things to be over-ridden externally to the library
// but still allow command line --args to pass debugging settings
//
// I also have a generic sleep() and exit() in here because it's simple
//
// Usage:
//
// log("something", foo, bar)
// var DEBUG bool = true
// log(DEBUG, "something else", someOtherVariable) # if DEBUG == false, return doing nothing
// log(SPEW, "something else", someOtherVariable) # this get's sent to spew.Dump(). Very useful for debugging!
//
package dnssecsocket package dnssecsocket
import ( import (
"os" witlog "git.wit.org/wit/gui/log"
golog "log"
"time"
"reflect"
"github.com/davecgh/go-spew/spew"
// "net"
) )
var LOGOFF bool = false // turn this off, all logging stops // various debugging flags
var WARN bool var logNow bool = true // useful for active development
var INFO bool var logError bool = true
var logWarn bool = false
var logInfo bool = false
var logVerbose bool = false
type spewt struct { var SPEW witlog.Spewt
a bool
}
var SPEW spewt // var log interface{}
/*
sleep() # you know what this does? sleeps for 1 second. yep. dump. easy.
sleep(.1) # you know what this does? yes, it sleeps for 1/10th of a second
*/
func sleep(a ...any) {
if (a == nil) {
time.Sleep(time.Second)
return
}
log(args.Verbose, "sleep", a[0])
switch a[0].(type) {
case int:
time.Sleep(time.Duration(a[0].(int)) * time.Second)
case float64:
time.Sleep(time.Duration(a[0].(float64) * 1000) * time.Millisecond)
default:
log("sleep a[0], type = ", a[0], reflect.TypeOf(a[0]))
}
}
/*
exit() # yep. exits. I guess everything must be fine
exit(3) # I guess 3 it is then
exit("dont like apples") # ok. I'll make a note of that
*/
func exit(a ...any) {
log("exit", a)
//if (a) {
// os.Exit(a)
//}
os.Exit(0)
}
/*
I've spent, am spending, too much time thinking about 'logging'. 'log', 'logrus', 'zap', whatever.
I'm not twitter. i don't give a fuck about how many nanoseconds it takes to log. Anyway, this
implementation is probably faster than all of those because you just set one bool to FALSE
and it all stops.
Sometimes I need to capture to stdout, sometimes stdout can't
work because it doesn't exist for the user. This whole thing is a PITA. Then it's spread
over 8 million references in every .go file. I'm tapping out and putting
it in one place. here it is. Also, this makes having debug levels really fucking easy.
You can define whatever level of logging you want from anywhere (command line) etc.
log() # doesn't do anything
log(stuff) # sends it to whatever log you define in a single place. here is the place
*/
func log(a ...any) { func log(a ...any) {
if (LOGOFF) { witlog.Where = "wit/gui"
return witlog.Log(a...)
} }
if (a == nil) { func sleep(a ...any) {
return witlog.Sleep(a...)
}
var blah bool
if (reflect.TypeOf(a[0]) == reflect.TypeOf(blah)) {
// golog.Println("\t a[0] = bool")
if (a[0] == false) {
return
}
a = a[1:]
} }
if (reflect.TypeOf(a[0]) == reflect.TypeOf(SPEW)) { func exit(a ...any) {
a = a[1:] log(logError, "got to log() exit")
spew.Dump(a) witlog.Exit(a...)
return
}
golog.Println(a...)
// golog.Println("\t a[0] =", a[0])
// for argNum, arg := range a {
// golog.Println("\t", argNum, arg)
// }
} }