github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/debug/debug.go (about)

     1  package debug
     2  
     3  import (
     4  	"encoding/json"
     5  	"log"
     6  )
     7  
     8  // Enabled is a flag used for debugging murex code. This can be enabled at
     9  // startup by a `--debug` flag or during runtime with `debug on`.
    10  var Enabled bool
    11  
    12  // Log writes a debug message
    13  func Log(data ...interface{}) {
    14  	if Enabled {
    15  		log.Println(data...)
    16  	}
    17  }
    18  
    19  // Json encode an object then write it as a debug message
    20  func Json(context string, data interface{}) {
    21  	if Enabled {
    22  		b, _ := json.MarshalIndent(data, "", "\t")
    23  		Log(context, "JSON:"+string(b))
    24  	}
    25  }
    26  
    27  // Dump is used for runtime output of the status of various debug modes
    28  func Dump() interface{} {
    29  	type status struct {
    30  		Debug bool
    31  	}
    32  
    33  	return status{
    34  		Debug: Enabled,
    35  	}
    36  }