-
Notifications
You must be signed in to change notification settings - Fork 23
/
console.go
48 lines (40 loc) · 1.26 KB
/
console.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package resultlog
import (
"encoding/json"
"github.com/caraml-dev/turing/engines/router/missionctl/errors"
"github.com/caraml-dev/turing/engines/router/missionctl/log"
"github.com/caraml-dev/turing/engines/router/missionctl/log/resultlog/proto/turing"
)
// ConsoleLogger generates instance of ConsoleLog for logging results
type ConsoleLogger struct{}
// NewConsoleLogger generates an instance of ConsoleLogger
func NewConsoleLogger() *ConsoleLogger {
return &ConsoleLogger{}
}
// write logs the given TuringResultLogEntry to the console
func (*ConsoleLogger) write(turLogEntry *turing.TuringResultLogMessage) error {
// Get context-specific upiLogger
logger := log.Glob()
var kvPairs map[string]interface{}
// Marshal into bytes
bytes, err := protoJSONMarshaller.Marshal(turLogEntry)
if err != nil {
return errors.Wrapf(err, "Error marshaling the result log")
}
// Unmarshal into map[string]interface{}
err = json.Unmarshal(bytes, &kvPairs)
if err != nil {
return errors.Wrapf(err, "Error unmarshaling the result log")
}
if err != nil {
return err
}
// Copy keys and values into an array
data := []interface{}{}
for k, v := range kvPairs {
data = append(data, k, v)
}
// Write the log
logger.Infow("Turing Request Summary", data...)
return nil
}