@@ -146,13 +146,7 @@ func runEnumCommand(clArgs []string) {
146
146
createOutputDirectory (cfg )
147
147
148
148
dir := config .OutputDirectory (cfg .Dir )
149
- // Setup logging
150
- var logfile string
151
- if args .Filepaths .LogFile != "" {
152
- logfile = args .Filepaths .LogFile
153
- }
154
- l := selectLogger (dir , logfile )
155
-
149
+ l := selectLogger (dir , args .Filepaths .LogFile )
156
150
// Create the client that will provide a connection to the engine
157
151
url := "http://localhost:4000/graphql"
158
152
if cfg .EngineAPI != nil && cfg .EngineAPI .URL != "" {
@@ -226,6 +220,47 @@ loop:
226
220
progress .Finish ()
227
221
}
228
222
223
+ func writeLogMessage (l * slog.Logger , message string ) {
224
+ logstr := channelJSONLog (message )
225
+ if logstr == "" {
226
+ return
227
+ }
228
+
229
+ record , err := format .JSONLogToRecord (logstr )
230
+ if err != nil {
231
+ return
232
+ }
233
+
234
+ ctx := context .Background ()
235
+ if l .Handler ().Enabled (ctx , record .Level ) {
236
+ l .Handler ().Handle (ctx , record )
237
+ }
238
+ }
239
+
240
+ func channelJSONLog (data string ) string {
241
+ j := make (map [string ]interface {})
242
+ if err := json .Unmarshal ([]byte (data ), & j ); err != nil {
243
+ return ""
244
+ }
245
+
246
+ var logstr string
247
+ // check that this is a log message sent over the sub channel
248
+ if p , found := j ["payload" ]; ! found {
249
+ return ""
250
+ } else if pmap , ok := p .(map [string ]interface {}); ! ok {
251
+ return ""
252
+ } else if d , found := pmap ["data" ]; ! found {
253
+ return ""
254
+ } else if dmap , ok := d .(map [string ]interface {}); ! ok {
255
+ return ""
256
+ } else if lm , found := dmap ["logMessages" ]; ! found {
257
+ return ""
258
+ } else if lmstr , ok := lm .(string ); ok {
259
+ logstr = lmstr
260
+ }
261
+ return logstr
262
+ }
263
+
229
264
func argsAndConfig (clArgs []string ) (* config.Config , * enumArgs ) {
230
265
args := enumArgs {
231
266
AltWordList : stringset .New (),
@@ -316,59 +351,6 @@ func argsAndConfig(clArgs []string) (*config.Config, *enumArgs) {
316
351
return cfg , & args
317
352
}
318
353
319
- func writeLogMessage (l * slog.Logger , logstr string ) {
320
- j := make (map [string ]interface {})
321
- if err := json .Unmarshal ([]byte (logstr ), & j ); err != nil {
322
- return
323
- }
324
- // check that this is a log message sent over the subscription channel
325
- if p , found := j ["payload" ]; ! found {
326
- return
327
- } else if pmap , ok := p .(map [string ]interface {}); ! ok {
328
- return
329
- } else if d , found := pmap ["data" ]; ! found {
330
- return
331
- } else if dmap , ok := d .(map [string ]interface {}); ! ok {
332
- return
333
- } else if lm , found := dmap ["logMessages" ]; ! found {
334
- return
335
- } else if lmmap , ok := lm .(map [string ]interface {}); ! ok {
336
- return
337
- } else {
338
- // set our json map to the log message within the channel data
339
- j = lmmap
340
- }
341
- delete (j , slog .TimeKey )
342
- delete (j , slog .SourceKey )
343
-
344
- var level slog.Level
345
- if val , found := j [slog .LevelKey ]; ! found {
346
- return
347
- } else if str , ok := val .(string ); ! ok {
348
- return
349
- } else if level .UnmarshalText ([]byte (str )) != nil {
350
- return
351
- }
352
- delete (j , slog .LevelKey )
353
-
354
- var msg string
355
- if val , found := j [slog .MessageKey ]; ! found {
356
- return
357
- } else if str , ok := val .(string ); ! ok {
358
- return
359
- } else {
360
- msg = str
361
- }
362
- delete (j , slog .MessageKey )
363
-
364
- var pc uintptr
365
- ctx := context .Background ()
366
- r := slog .NewRecord (time .Now (), level , msg , pc )
367
- if l .Handler ().Enabled (ctx , level ) {
368
- l .Handler ().Handle (ctx , r )
369
- }
370
- }
371
-
372
354
// Obtain parameters from provided input files
373
355
func processEnumInputFiles (args * enumArgs ) error {
374
356
getList := func (fp []string , name string , s * stringset.Set ) error {
0 commit comments