From b1451484712984353785340499eb0320f19f7905 Mon Sep 17 00:00:00 2001 From: Noah Metz Date: Mon, 26 Jun 2023 22:39:24 -0600 Subject: [PATCH] Added Logj --- graph.go | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/graph.go b/graph.go index c14ce94..27ba55c 100644 --- a/graph.go +++ b/graph.go @@ -27,6 +27,8 @@ type Logger interface { Logf(component string, format string, items ... interface{}) // Log a map of attributes and a format string Logm(component string, fields map[string]interface{}, format string, items ... interface{}) + // Log a structure to a file by marshalling and unmarshalling the json + Logj(component string, s interface{}, format string, items ... interface{}) } func NewConsoleLogger(components []string) *ConsoleLogger { @@ -93,6 +95,19 @@ func (logger * ConsoleLogger) Logf(component string, format string, items ... in } } +func (logger * ConsoleLogger) Logj(component string, s interface{}, format string, items ... interface{}) { + m := map[string]interface{}{} + ser, err := json.Marshal(s) + if err != nil { + panic("LOG_MARSHAL_ERR") + } + err = json.Unmarshal(ser, &m) + if err != nil { + panic("LOG_UNMARSHAL_ERR") + } + logger.Logm(component, m, format, items...) +} + type NodeID string // Generate a random id func RandID() NodeID {