Commit 0e41f4d80b46656f9b9466db825c978785251989
1 parent
0beb2d1fe7
Exists in
master
and in
1 other branch
refactored due to new gologger interface
Showing
1 changed file
with
22 additions
and
11 deletions
Show diff stats
json_utility.go
... | ... | @@ -10,6 +10,8 @@ import ( |
10 | 10 | "sync" |
11 | 11 | "time" |
12 | 12 | |
13 | + "git.to-net.rs/marko.tikvic/gologger" | |
14 | + | |
13 | 15 | "gopkg.in/rana/ora.v4" |
14 | 16 | ) |
15 | 17 | |
... | ... | @@ -24,6 +26,16 @@ var ( |
24 | 26 | inited bool |
25 | 27 | ) |
26 | 28 | |
29 | +var logger *gologger.Logger | |
30 | + | |
31 | +func init() { | |
32 | + var err error | |
33 | + logger, err = gologger.New("webutility", gologger.MaxLogSize100KB) | |
34 | + if err != nil { | |
35 | + fmt.Printf("webutility: %s\n", err.Error()) | |
36 | + } | |
37 | +} | |
38 | + | |
27 | 39 | type LangMap map[string]map[string]string |
28 | 40 | |
29 | 41 | type Field struct { |
... | ... | @@ -120,11 +132,11 @@ func UpdateEntityModels(command string) (total, upd, add int, err error) { |
120 | 132 | k) |
121 | 133 | |
122 | 134 | if err != nil { |
123 | - fmt.Printf("webutility: update metadata: prep and exe: %v\n", err) | |
135 | + logger.Log("webutility: update metadata: prep and exe: %v\n", err) | |
124 | 136 | continue |
125 | 137 | } |
126 | 138 | upd++ |
127 | - fmt.Printf("webutility: updated %s payload model\n", k) | |
139 | + logger.Log("webutility: updated %s payload model\n", k) | |
128 | 140 | } |
129 | 141 | |
130 | 142 | blankPayload, _ := json.Marshal(Payload{}) |
... | ... | @@ -138,12 +150,12 @@ func UpdateEntityModels(command string) (total, upd, add int, err error) { |
138 | 150 | string(updateQue[k])) |
139 | 151 | |
140 | 152 | if err != nil { |
141 | - fmt.Printf("webutility: add metadata: prep and exe: %v\n", err) | |
153 | + logger.Log("webutility: add metadata: prep and exe: %v\n", err) | |
142 | 154 | continue |
143 | 155 | } |
144 | 156 | metadata[k] = Payload{} |
145 | 157 | add++ |
146 | - fmt.Printf("webutility: added %s to the payload models\n", k) | |
158 | + logger.Log("webutility: added %s to the payload models\n", k) | |
147 | 159 | |
148 | 160 | } |
149 | 161 | |
... | ... | @@ -227,15 +239,14 @@ func initMetadata(project string) error { |
227 | 239 | p := Payload{} |
228 | 240 | err := json.Unmarshal(load, &p) |
229 | 241 | if err != nil { |
230 | - fmt.Printf("couldn't init: '%s' metadata\n", name) | |
242 | + logger.Log("couldn't init: '%s' metadata: %s\n%s\n", name, err.Error(), rset.Row[1].(string)) | |
231 | 243 | } else { |
232 | 244 | success++ |
233 | 245 | metadata[name] = p |
234 | 246 | } |
235 | 247 | count++ |
236 | 248 | } |
237 | - fmt.Printf("webutility: successfully loaded %d/%d (%.1f%%) entities\n", | |
238 | - success, count, float32(success)/float32(count)*100.0) | |
249 | + logger.Log("webutility: successfully loaded %d/%d (%.1f%%) entities\n", success, count, float32(success)/float32(count)*100.0) | |
239 | 250 | |
240 | 251 | return nil |
241 | 252 | } |
... | ... | @@ -252,7 +263,7 @@ func hotload(n int) { |
252 | 263 | ora.I64, |
253 | 264 | ora.S) |
254 | 265 | if err != nil { |
255 | - fmt.Fprintf(os.Stderr, "hotload failed: %v\n", err) | |
266 | + logger.Log("hotload failed: %v\n", err) | |
256 | 267 | time.Sleep(time.Duration(n) * time.Second) |
257 | 268 | continue |
258 | 269 | } |
... | ... | @@ -277,7 +288,7 @@ func hotload(n int) { |
277 | 288 | stmt.Close() |
278 | 289 | |
279 | 290 | if rset.Err() != nil { |
280 | - fmt.Fprintf(os.Stderr, "hotload rset error: %v\n", rset.Err()) | |
291 | + logger.Log("hotload rset error: %v\n", rset.Err()) | |
281 | 292 | time.Sleep(time.Duration(n) * time.Second) |
282 | 293 | continue |
283 | 294 | } |
... | ... | @@ -304,7 +315,7 @@ func refreshMetadata(entities []string) { |
304 | 315 | ora.S) |
305 | 316 | |
306 | 317 | if err != nil { |
307 | - fmt.Printf("webutility: refresh: prep: %v\n", err) | |
318 | + logger.Log("webutility: refresh: prep: %v\n", err) | |
308 | 319 | stmt.Close() |
309 | 320 | continue |
310 | 321 | } |
... | ... | @@ -321,7 +332,7 @@ func refreshMetadata(entities []string) { |
321 | 332 | p := Payload{} |
322 | 333 | err := json.Unmarshal(load, &p) |
323 | 334 | if err != nil { |
324 | - fmt.Printf("couldn't refresh: '%s' metadata\n", e) | |
335 | + logger.Log("couldn't refresh: '%s' metadata: %s\n%s\n", e, err.Error(), rset.Row[0].(string)) | |
325 | 336 | } else { |
326 | 337 | metadata[e] = p |
327 | 338 | } | ... | ... |