@@ -19,7 +19,7 @@ type Instance struct {
19
19
ConcurrencyCtrl int
20
20
UnderlyingInstance gbus.Saga
21
21
MsgToMethodMap []* MsgToFuncPair
22
- Log logrus.FieldLogger
22
+ logger logrus.FieldLogger
23
23
/*
24
24
Will hold the service name that sent the command or event that started the saga
25
25
*/
@@ -36,6 +36,14 @@ type Instance struct {
36
36
StartedByRPCID string
37
37
}
38
38
39
+ func (si * Instance ) log () logrus.FieldLogger {
40
+ if si .logger == nil {
41
+ return logrus .WithField ("id" , si .ID )
42
+ }
43
+
44
+ return si .logger
45
+ }
46
+
39
47
func (si * Instance ) invoke (exchange , routingKey string , invocation * sagaInvocation , message * gbus.BusMessage ) error {
40
48
41
49
methodsToInvoke := si .getSagaMethodNameToInvoke (exchange , routingKey , message )
@@ -55,10 +63,10 @@ func (si *Instance) invoke(exchange, routingKey string, invocation *sagaInvocati
55
63
params := make ([]reflect.Value , 0 )
56
64
params = append (params , reflect .ValueOf (invocation ), valueOfMessage )
57
65
method := reflectedVal .MethodByName (methodName )
58
- if invocation . Log () == nil {
66
+ if si . log () == nil {
59
67
panic ("here" )
60
68
}
61
- invocation . Log ().WithFields (logrus.Fields {
69
+ si . log ().WithFields (logrus.Fields {
62
70
"method_name" : methodName , "saga_id" : si .ID ,
63
71
}).Info ("invoking method on saga" )
64
72
@@ -78,13 +86,13 @@ func (si *Instance) invoke(exchange, routingKey string, invocation *sagaInvocati
78
86
return val .Interface ().(error )
79
87
}
80
88
return nil
81
- }, methodName , message .PayloadFQN , invocation . Log ())
89
+ }, methodName , message .PayloadFQN , si . log ())
82
90
83
91
if err != nil {
84
92
return err
85
93
}
86
94
87
- invocation . Log ().WithFields (logrus.Fields {
95
+ si . log ().WithFields (logrus.Fields {
88
96
"method_name" : methodName , "saga_id" : si .ID ,
89
97
}).Info ("saga instance invoked" )
90
98
}
0 commit comments