@@ -3,9 +3,9 @@ package goengine
33import (
44 "fmt"
55
6- log "github.com/Sirupsen/logrus"
76 "github.com/hellofresh/goengine/reflection"
87 "github.com/pborman/uuid"
8+ log "github.com/sirupsen/logrus"
99)
1010
1111type AggregateRoot interface {
@@ -17,10 +17,10 @@ type AggregateRoot interface {
1717}
1818
1919type AggregateRootBased struct {
20- ID string
21- version int
22- source interface {}
23- uncommitedEvents []* DomainMessage
20+ ID string
21+ version int
22+ source interface {}
23+ uncommittedEvents []* DomainMessage
2424}
2525
2626// NewAggregateRootBased constructor
@@ -46,18 +46,21 @@ func (r *AggregateRootBased) SetVersion(version int) {
4646}
4747
4848func (r * AggregateRootBased ) GetUncommittedEvents () []* DomainMessage {
49- stream := r .uncommitedEvents
50- r .uncommitedEvents = nil
51- log .Debugf ( "%d Uncommited events cleaned " , len (stream ))
49+ stream := r .uncommittedEvents
50+ r .uncommittedEvents = nil
51+ log .WithField ( "count " , len (stream )). Debug ( "Uncommitted events cleaned" )
5252
5353 return stream
5454}
5555
5656func (r * AggregateRootBased ) Apply (event DomainEvent ) {
5757 t := reflection .TypeOf (event )
58- log .Debugf ("source: %+v; MethodName: %+v; event: %+v" , r .source , fmt .Sprintf ("When%s" , t .Name ()), event )
59- reflection .CallMethod (r .source , fmt .Sprintf ("When%s" , t .Name ()), event )
60- log .Debugf ("Event %s applied" , t .Name ())
58+ methodName := fmt .Sprintf ("When%s" , t .Name ())
59+
60+ entry := log .WithFields (log.Fields {"source" : fmt .Sprintf ("%+v" , r .source ), "method" : methodName , "event" : fmt .Sprintf ("%+v" , event )})
61+ entry .Debug ("Applying event" )
62+ reflection .CallMethod (r .source , methodName , event )
63+ entry .Debug ("Event applied" )
6164}
6265
6366func (r * AggregateRootBased ) RecordThat (event DomainEvent ) {
@@ -68,6 +71,6 @@ func (r *AggregateRootBased) RecordThat(event DomainEvent) {
6871
6972func (r * AggregateRootBased ) Record (event DomainEvent ) {
7073 message := RecordNow (r .ID , r .version , event )
71- r .uncommitedEvents = append (r .uncommitedEvents , message )
74+ r .uncommittedEvents = append (r .uncommittedEvents , message )
7275 log .Debug ("Event recorded" )
7376}
0 commit comments