@@ -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,23 @@ 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 .Any ("notification" , notification )
166+ }
162167 switch resolveErrorAction (a .projectionErrorHandler , notification , err ) {
163168 case errorFail :
164- logger .Debug ("ProcessHandler->ErrorHandler: marking projection as failed" )
169+ a . logger .Debug ("ProcessHandler->ErrorHandler: marking projection as failed" , logFields )
165170 return a .markProjectionAsFailed (ctx , notification )
166171 case errorIgnore :
167- logger .Debug ("ProcessHandler->ErrorHandler: ignoring error" )
172+ a . logger .Debug ("ProcessHandler->ErrorHandler: ignoring error" , logFields )
168173 return nil
169174 case errorRetry :
170- logger .Debug ("ProcessHandler->ErrorHandler: re-queueing notification" )
175+ a . logger .Debug ("ProcessHandler->ErrorHandler: re-queueing notification" , logFields )
171176 return queue (ctx , notification )
172177 }
173178
174- logger .Debug ("ProcessHandler->ErrorHandler: error fallthrough" )
179+ a . logger .Debug ("ProcessHandler->ErrorHandler: error fallthrough" , logFields )
175180 return err
176181}
177182
@@ -183,7 +188,9 @@ func (a *AggregateProjector) triggerOutOfSyncProjections(ctx context.Context, qu
183188 }
184189 defer func () {
185190 if err := conn .Close (); err != nil {
186- a .logger .WithError (err ).Warn ("failed to db close LoadOutOfSync connection" )
191+ a .logger .Warn ("failed to db close LoadOutOfSync connection" , func (e goengine.LoggerEntry ) {
192+ e .Error (err )
193+ })
187194 }
188195 }()
189196
@@ -193,7 +200,9 @@ func (a *AggregateProjector) triggerOutOfSyncProjections(ctx context.Context, qu
193200 }
194201 defer func () {
195202 if err := rows .Close (); err != nil {
196- a .logger .WithError (err ).Error ("failed to close LoadOutOfSync rows" )
203+ a .logger .Error ("failed to close LoadOutOfSync rows" , func (e goengine.LoggerEntry ) {
204+ e .Error (err )
205+ })
197206 }
198207 }()
199208
@@ -219,13 +228,17 @@ func (a *AggregateProjector) triggerOutOfSyncProjections(ctx context.Context, qu
219228 AggregateID : aggregateID ,
220229 }
221230
222- logger := a .logger .WithField ("notification" , notification )
223231 if err := queue (ctx , notification ); err != nil {
224- logger .WithError (err ).Error ("failed to queue notification" )
232+ a .logger .Error ("failed to queue notification" , func (e goengine.LoggerEntry ) {
233+ e .Error (err )
234+ e .Any ("notification" , notification )
235+ })
225236 return err
226237 }
227238
228- a .logger .Debug ("send catchup" )
239+ a .logger .Debug ("send catchup" , func (e goengine.LoggerEntry ) {
240+ e .Any ("notification" , notification )
241+ })
229242 }
230243
231244 return rows .Close ()
@@ -239,7 +252,9 @@ func (a *AggregateProjector) markProjectionAsFailed(ctx context.Context, notific
239252
240253 defer func () {
241254 if err := conn .Close (); err != nil {
242- a .logger .WithError (err ).Warn ("failed to db close failure connection" )
255+ a .logger .Warn ("failed to db close failure connection" , func (e goengine.LoggerEntry ) {
256+ e .Error (err )
257+ })
243258 }
244259 }()
245260
0 commit comments