diff options
Diffstat (limited to 'toolkit/gocui')
| -rw-r--r-- | toolkit/gocui/debug.go | 2 | ||||
| -rw-r--r-- | toolkit/gocui/log.go | 125 |
2 files changed, 8 insertions, 119 deletions
diff --git a/toolkit/gocui/debug.go b/toolkit/gocui/debug.go index 1e424f7..b38fd83 100644 --- a/toolkit/gocui/debug.go +++ b/toolkit/gocui/debug.go @@ -88,6 +88,7 @@ func widgetDump(b bool, w *toolkit.Widget) { return } + /* log(b, "widget.Name =", w.Name) // log(b, "widget.Action =", w.Action) log(b, "widget.Type =", w.Type) @@ -98,6 +99,7 @@ func widgetDump(b bool, w *toolkit.Widget) { log(b, "widget.Height =", w.Height) log(b, "widget.X =", w.X) log(b, "widget.Y =", w.Y) + */ } /* diff --git a/toolkit/gocui/log.go b/toolkit/gocui/log.go index afd1280..527d057 100644 --- a/toolkit/gocui/log.go +++ b/toolkit/gocui/log.go @@ -1,135 +1,22 @@ -// -// version v1.3 -// -// I like things to be easy. -// -// combining logging inside of a gui made me do this -// -// 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 main import ( "os" - golog "log" - "time" - "reflect" - "github.com/davecgh/go-spew/spew" + witlog "git.wit.org/wit/gui/log" ) -var LOGOFF bool = false // turn this off, all logging stops -var WARN bool -var INFO bool - -type spewt struct { - a bool +func log(a ...any) { + witlog.Log(a...) } -var SPEW spewt - - -/* - 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(true, "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])) - } + witlog.Sleep(a...) } -/* - 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(true, "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) { - if (LOGOFF) { - return - } - - if (a == nil) { - return - } - var tbool bool - if (reflect.TypeOf(a[0]) == reflect.TypeOf(tbool)) { - if (a[0] == false) { - return - } - a[0] = "GUI/Toolkit/gocui" - } - - if (reflect.TypeOf(a[0]) == reflect.TypeOf(SPEW)) { - // a = a[1:] - a[0] = "GUI/Toolkit/gocui" - if (debugToolkit) { - scs := spew.ConfigState{MaxDepth: 1} - scs.Dump(a) - // spew.Dump(a) - } - return - } - - golog.Println(a...) -} - -func logindent(depth int, format string, a ...interface{}) { - var tabs string - for i := 0; i < depth; i++ { - tabs = tabs + format - } - - // newFormat := tabs + strconv.Itoa(depth) + " " + format - newFormat := tabs + format - log(debugToolkit, newFormat, a) + witlog.Exit(a...) } func setOutput(f *os.File) { - golog.SetOutput(f) + witlog.SetOutput(f) } |
