From 0e41f4d80b46656f9b9466db825c978785251989 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Marko=20Tikvi=C4=87?= Date: Mon, 26 Feb 2018 11:10:21 +0100 Subject: [PATCH] refactored due to new gologger interface --- json_utility.go | 33 ++++++++++++++++++++++----------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/json_utility.go b/json_utility.go index da109e1..4f75eb0 100644 --- a/json_utility.go +++ b/json_utility.go @@ -10,6 +10,8 @@ import ( "sync" "time" + "git.to-net.rs/marko.tikvic/gologger" + "gopkg.in/rana/ora.v4" ) @@ -24,6 +26,16 @@ var ( inited bool ) +var logger *gologger.Logger + +func init() { + var err error + logger, err = gologger.New("webutility", gologger.MaxLogSize100KB) + if err != nil { + fmt.Printf("webutility: %s\n", err.Error()) + } +} + type LangMap map[string]map[string]string type Field struct { @@ -120,11 +132,11 @@ func UpdateEntityModels(command string) (total, upd, add int, err error) { k) if err != nil { - fmt.Printf("webutility: update metadata: prep and exe: %v\n", err) + logger.Log("webutility: update metadata: prep and exe: %v\n", err) continue } upd++ - fmt.Printf("webutility: updated %s payload model\n", k) + logger.Log("webutility: updated %s payload model\n", k) } blankPayload, _ := json.Marshal(Payload{}) @@ -138,12 +150,12 @@ func UpdateEntityModels(command string) (total, upd, add int, err error) { string(updateQue[k])) if err != nil { - fmt.Printf("webutility: add metadata: prep and exe: %v\n", err) + logger.Log("webutility: add metadata: prep and exe: %v\n", err) continue } metadata[k] = Payload{} add++ - fmt.Printf("webutility: added %s to the payload models\n", k) + logger.Log("webutility: added %s to the payload models\n", k) } @@ -227,15 +239,14 @@ func initMetadata(project string) error { p := Payload{} err := json.Unmarshal(load, &p) if err != nil { - fmt.Printf("couldn't init: '%s' metadata\n", name) + logger.Log("couldn't init: '%s' metadata: %s\n%s\n", name, err.Error(), rset.Row[1].(string)) } else { success++ metadata[name] = p } count++ } - fmt.Printf("webutility: successfully loaded %d/%d (%.1f%%) entities\n", - success, count, float32(success)/float32(count)*100.0) + logger.Log("webutility: successfully loaded %d/%d (%.1f%%) entities\n", success, count, float32(success)/float32(count)*100.0) return nil } @@ -252,7 +263,7 @@ func hotload(n int) { ora.I64, ora.S) if err != nil { - fmt.Fprintf(os.Stderr, "hotload failed: %v\n", err) + logger.Log("hotload failed: %v\n", err) time.Sleep(time.Duration(n) * time.Second) continue } @@ -277,7 +288,7 @@ func hotload(n int) { stmt.Close() if rset.Err() != nil { - fmt.Fprintf(os.Stderr, "hotload rset error: %v\n", rset.Err()) + logger.Log("hotload rset error: %v\n", rset.Err()) time.Sleep(time.Duration(n) * time.Second) continue } @@ -304,7 +315,7 @@ func refreshMetadata(entities []string) { ora.S) if err != nil { - fmt.Printf("webutility: refresh: prep: %v\n", err) + logger.Log("webutility: refresh: prep: %v\n", err) stmt.Close() continue } @@ -321,7 +332,7 @@ func refreshMetadata(entities []string) { p := Payload{} err := json.Unmarshal(load, &p) if err != nil { - fmt.Printf("couldn't refresh: '%s' metadata\n", e) + logger.Log("couldn't refresh: '%s' metadata: %s\n%s\n", e, err.Error(), rset.Row[0].(string)) } else { metadata[e] = p } -- 1.8.1.2