summaryrefslogtreecommitdiff
path: root/log
diff options
context:
space:
mode:
authorJeff Carr <[email protected]>2023-03-29 23:03:04 -0500
committerJeff Carr <[email protected]>2023-03-29 23:03:04 -0500
commit4e28cde838683188bfbd9222746409538828592d (patch)
tree3c84fffc14352329bc41e6b58910ff278c99f08c /log
parentd4787a1ebdd08359746516dbb72f1feaf95be5b6 (diff)
add semi-working gocuiv0.7.4
commit 947169df5a22c9f9b53f825764747f648c70ff1e Author: Jeff Carr <[email protected]> Date: Wed Mar 29 22:44:08 2023 -0500 ready for version v0.7.4 start deprecating toolkit.Widget switch to variable name 'ParentId' use 'ActionType' and 'WidgetType' preliminary redraw() final definition of variables 'Name' and 'Text' more cleaning of the code remove lots of dumb code bind 'd' key press to dump out debugging info early color handling in gocui! Signed-off-by: Jeff Carr <[email protected]> commit 6013fde8332e8ecbffaf1a0977ba2e1da8ea8775 Author: Jeff Carr <[email protected]> Date: Sun Mar 26 17:19:20 2023 -0500 improvements towards a working dns control panel democui has the help menu try to add mouse support to gocui make a direct access method Margin() and Pad() tests add SPEW also push devel branch to github Signed-off-by: Jeff Carr <[email protected]> commit 6f91f5e080e06cdc0f34b13d23e5fd16ea37259a Author: Jeff Carr <[email protected]> Date: Fri Mar 24 20:14:18 2023 -0500 starting to try safe chan and goroutines fix tab title's right before attempting to add chan goroutines removed "where" widget pointer box added to tab experiement with log as it's own repo Signed-off-by: Jeff Carr <[email protected]> Signed-off-by: Jeff Carr <[email protected]>
Diffstat (limited to 'log')
-rw-r--r--log/log.go149
1 files changed, 149 insertions, 0 deletions
diff --git a/log/log.go b/log/log.go
new file mode 100644
index 0000000..9862291
--- /dev/null
+++ b/log/log.go
@@ -0,0 +1,149 @@
+package witlog
+//
+// version v1.2
+//
+// 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!
+//
+
+import (
+ "os"
+ "runtime"
+ "runtime/pprof"
+ golog "log"
+ "time"
+ "reflect"
+ "github.com/davecgh/go-spew/spew"
+ // "net"
+)
+
+// various debugging flags
+var LogNow bool = true // useful for active development
+var LogError bool = true
+var LogWarn bool = false
+var LogInfo bool = false
+var LogVerbose bool = false
+var LogSleep bool = false
+
+var LOGOFF bool = false // turn this off, all logging stops
+var debugToolkit bool = false // does spew stuff?
+
+var Where string = "gui/log"
+
+type Spewt struct {
+ a bool
+}
+
+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(LogSleep, "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(LogError, "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] = Where
+ }
+
+ if (reflect.TypeOf(a[0]) == reflect.TypeOf(SPEW)) {
+ // a = a[1:]
+ a[0] = Where
+ if (debugToolkit) {
+ scs := spew.ConfigState{MaxDepth: 1}
+ scs.Dump(a)
+ // spew.Dump(a)
+ }
+ return
+ }
+
+ golog.Println(a...)
+}
+
+func loggo() {
+ pprof.Lookup("goroutine").WriteTo(os.Stdout, 1)
+ golog.Println("runtime.NumGoroutine() = ", runtime.NumGoroutine())
+}
+
+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)
+}
+
+func SetOutput(f *os.File) {
+ golog.SetOutput(f)
+}