forked from 0xPolygonHermez/zkevm-node
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheventlog.go
53 lines (47 loc) · 1.42 KB
/
eventlog.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
49
50
51
52
53
package event
import (
"context"
"encoding/json"
"time"
"github.com/0xPolygonHermez/zkevm-node/log"
"github.com/0xPolygonHermez/zkevm-node/state/runtime/executor"
)
// EventLog is the main struct for the event log
type EventLog struct {
cfg Config
storage Storage
}
// NewEventLog creates and initializes an instance of EventLog
func NewEventLog(cfg Config, storage Storage) *EventLog {
return &EventLog{
cfg: cfg,
storage: storage,
}
}
// LogEvent is used to store an event for runtime debugging
func (e *EventLog) LogEvent(ctx context.Context, event *Event) error {
return e.storage.LogEvent(ctx, event)
}
// LogExecutorError is used to store Executor error for runtime debugging
func (e *EventLog) LogExecutorError(ctx context.Context, responseError executor.ExecutorError, processBatchRequest *executor.ProcessBatchRequest) {
timestamp := time.Now()
log.Errorf("error found in the executor: %v at %v", responseError, timestamp)
payload, err := json.Marshal(processBatchRequest)
if err != nil {
log.Errorf("error marshaling payload: %v", err)
} else {
event := &Event{
ReceivedAt: timestamp,
Source: Source_Node,
Component: Component_Executor,
Level: Level_Error,
EventID: EventID_ExecutorError,
Description: responseError.String(),
Json: string(payload),
}
err = e.storage.LogEvent(ctx, event)
if err != nil {
log.Errorf("error storing event: %v", err)
}
}
}