-
Notifications
You must be signed in to change notification settings - Fork 4
/
logger_machine.go
98 lines (81 loc) · 2.69 KB
/
logger_machine.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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package insconveyor
import (
"context"
"github.com/insolar/assured-ledger/ledger-core/conveyor/smachine"
"github.com/insolar/assured-ledger/ledger-core/instrumentation/convlog"
"github.com/insolar/assured-ledger/ledger-core/instrumentation/inslogger"
"github.com/insolar/assured-ledger/ledger-core/log"
"github.com/insolar/assured-ledger/ledger-core/log/global"
"github.com/insolar/assured-ledger/ledger-core/vanilla/throw"
)
type ConveyorLoggerFactory struct {
}
func (c ConveyorLoggerFactory) CreateStepLogger(ctx context.Context, _ smachine.StateMachine, traceID smachine.TracerID) smachine.StepLogger {
ctxWithTrace, logger := inslogger.WithTraceField(ctx, traceID)
return &ConveyorLogger{
tracerCtx: ctxWithTrace,
tracerID: traceID,
logger: logger,
}
}
type LogInternal struct {
*log.Msg `txt:"internal"`
Message string `fmt:"internal - %s"`
Component string `txt:"sm"`
MachineID string
SlotID smachine.SlotID
SlotStepNo uint32
CycleNo uint32
Error error `opt:""`
Backtrace string `opt:""`
}
func (ConveyorLoggerFactory) LogMachineInternal(slotMachineData smachine.SlotMachineData, msg string) {
backtrace := ""
level := log.WarnLevel
if slotMachineData.Error != nil {
level = log.ErrorLevel
if st := throw.DeepestStackTraceOf(slotMachineData.Error); st != nil {
st = throw.MinimizeStackTrace(st, convlog.StackMinimizePackage, true)
backtrace = st.StackTraceAsText()
}
}
global.Logger().Eventm(level, LogInternal{
Message: msg,
MachineID: slotMachineData.StepNo.MachineID(),
CycleNo: slotMachineData.CycleNo,
SlotID: slotMachineData.StepNo.SlotID(),
SlotStepNo: slotMachineData.StepNo.StepNo(),
Error: slotMachineData.Error,
Backtrace: backtrace,
})
}
type LogCritical struct {
*log.Msg `txt:"internal"`
Message string `fmt:"internal critical - %s"`
Component string `txt:"sm"`
MachineID string
SlotID smachine.SlotID
SlotStepNo uint32
CycleNo uint32
Error error `opt:""`
Backtrace string `opt:""`
}
func (ConveyorLoggerFactory) LogMachineCritical(slotMachineData smachine.SlotMachineData, msg string) {
backtrace := ""
if slotMachineData.Error != nil {
if st := throw.DeepestStackTraceOf(slotMachineData.Error); st != nil {
st = throw.MinimizeStackTrace(st, convlog.StackMinimizePackage, true)
backtrace = st.StackTraceAsText()
}
}
global.Logger().Errorm(LogCritical{
Message: msg,
MachineID: slotMachineData.StepNo.MachineID(),
CycleNo: slotMachineData.CycleNo,
SlotID: slotMachineData.StepNo.SlotID(),
SlotStepNo: slotMachineData.StepNo.StepNo(),
Error: slotMachineData.Error,
Backtrace: backtrace,
})
}
func (ConveyorLoggerFactory) LogStopping(*smachine.SlotMachine) {}