@@ -60,7 +60,9 @@ func NewAggregateProjector(
6060 if logger == nil {
6161 logger = goengine .NopLogger
6262 }
63- logger = logger .WithField ("projection" , projection )
63+ logger = logger .WithFields (func (e goengine.LoggerEntry ) {
64+ e .String ("projection" , projection .Name ())
65+ })
6466
6567 processor , err := internal .NewBackgroundProcessor (10 , 32 , logger )
6668 if err != nil {
@@ -158,20 +160,24 @@ func (a *AggregateProjector) processNotification(
158160 }
159161
160162 // Resolve the action to take based on the error that occurred
161- logger := a .logger .WithError (err ).WithField ("notification" , notification )
163+ logFields := func (e goengine.LoggerEntry ) {
164+ e .Error (err )
165+ e .Int64 ("notification.no" , notification .No )
166+ e .String ("notification.aggregate_id" , notification .AggregateID )
167+ }
162168 switch resolveErrorAction (a .projectionErrorHandler , notification , err ) {
163169 case errorFail :
164- logger .Debug ("ProcessHandler->ErrorHandler: marking projection as failed" )
170+ a . logger .Debug ("ProcessHandler->ErrorHandler: marking projection as failed" , logFields )
165171 return a .markProjectionAsFailed (ctx , notification )
166172 case errorIgnore :
167- logger .Debug ("ProcessHandler->ErrorHandler: ignoring error" )
173+ a . logger .Debug ("ProcessHandler->ErrorHandler: ignoring error" , logFields )
168174 return nil
169175 case errorRetry :
170- logger .Debug ("ProcessHandler->ErrorHandler: re-queueing notification" )
176+ a . logger .Debug ("ProcessHandler->ErrorHandler: re-queueing notification" , logFields )
171177 return queue (ctx , notification )
172178 }
173179
174- logger .Debug ("ProcessHandler->ErrorHandler: error fallthrough" )
180+ a . logger .Debug ("ProcessHandler->ErrorHandler: error fallthrough" , logFields )
175181 return err
176182}
177183
@@ -183,7 +189,9 @@ func (a *AggregateProjector) triggerOutOfSyncProjections(ctx context.Context, qu
183189 }
184190 defer func () {
185191 if err := conn .Close (); err != nil {
186- a .logger .WithError (err ).Warn ("failed to db close LoadOutOfSync connection" )
192+ a .logger .Warn ("failed to db close LoadOutOfSync connection" , func (e goengine.LoggerEntry ) {
193+ e .Error (err )
194+ })
187195 }
188196 }()
189197
@@ -193,7 +201,9 @@ func (a *AggregateProjector) triggerOutOfSyncProjections(ctx context.Context, qu
193201 }
194202 defer func () {
195203 if err := rows .Close (); err != nil {
196- a .logger .WithError (err ).Error ("failed to close LoadOutOfSync rows" )
204+ a .logger .Error ("failed to close LoadOutOfSync rows" , func (e goengine.LoggerEntry ) {
205+ e .Error (err )
206+ })
197207 }
198208 }()
199209
@@ -219,13 +229,19 @@ func (a *AggregateProjector) triggerOutOfSyncProjections(ctx context.Context, qu
219229 AggregateID : aggregateID ,
220230 }
221231
222- logger := a .logger .WithField ("notification" , notification )
223232 if err := queue (ctx , notification ); err != nil {
224- logger .WithError (err ).Error ("failed to queue notification" )
233+ a .logger .Error ("failed to queue notification" , func (e goengine.LoggerEntry ) {
234+ e .Error (err )
235+ e .Int64 ("notification.no" , notification .No )
236+ e .String ("notification.aggregate_id" , notification .AggregateID )
237+ })
225238 return err
226239 }
227240
228- a .logger .Debug ("send catchup" )
241+ a .logger .Debug ("send catchup" , func (e goengine.LoggerEntry ) {
242+ e .Int64 ("notification.no" , notification .No )
243+ e .String ("notification.aggregate_id" , notification .AggregateID )
244+ })
229245 }
230246
231247 return rows .Close ()
@@ -239,7 +255,9 @@ func (a *AggregateProjector) markProjectionAsFailed(ctx context.Context, notific
239255
240256 defer func () {
241257 if err := conn .Close (); err != nil {
242- a .logger .WithError (err ).Warn ("failed to db close failure connection" )
258+ a .logger .Warn ("failed to db close failure connection" , func (e goengine.LoggerEntry ) {
259+ e .Error (err )
260+ })
243261 }
244262 }()
245263
0 commit comments