mirror of
https://github.com/foxcpp/maddy.git
synced 2025-04-05 05:57:39 +03:00
Rework how error inspection and logging is done
Previous error reporting code was inconsistent in terms of what is logged, when and by whom. This caused several problems such as: logs missing important error context, duplicated error messages, too verbose messages, etc. Instead of logging all generated errors, module should log only errors it 'handles' somehow and does not simply pass it to the caller. This removes duplication, however, also it removes context information. To fix this, exterrors package was extended to provide utilities for error wrapping. These utilities provide ability to 'attach' arbitrary key-value ('fields') pairs to any error object while preserving the original value (using to Go 1.13 error handling primitives). In additional to solving problems described above this commit makes logs machine-readable, creating the possibility for automated analysis. Three new functions were added to the Logger object, providing loosely-typed structured logging. However, they do not completely replace plain logging and are used only where they are useful (to allow automated analysis of message processing logs). So, basically, instead of being logged god knows where and when, all context information is attached to the error object and then it is passed up until it is handled somewhere, at this point it is logged together with all context information and then discarded.
This commit is contained in:
parent
8c178f7d76
commit
cf9e81d8a1
24 changed files with 714 additions and 341 deletions
|
@ -216,7 +216,6 @@ func (dd *msgpipelineDelivery) AddRcpt(to string) error {
|
|||
}
|
||||
|
||||
if rcptBlock.rejectErr != nil {
|
||||
dd.log.Debugf("recipient %s rejected: %v", to, rcptBlock.rejectErr)
|
||||
return rcptBlock.rejectErr
|
||||
}
|
||||
|
||||
|
@ -248,10 +247,8 @@ func (dd *msgpipelineDelivery) AddRcpt(to string) error {
|
|||
}
|
||||
|
||||
if err := delivery.AddRcpt(to); err != nil {
|
||||
dd.log.Debugf("delivery.AddRcpt(%s) failure, Delivery object = %T: %v", to, delivery, err)
|
||||
return err
|
||||
}
|
||||
dd.log.Debugf("delivery.AddRcpt(%s) ok, Delivery object = %T", to, delivery)
|
||||
delivery.recipients = append(delivery.recipients, originalTo)
|
||||
}
|
||||
|
||||
|
@ -282,7 +279,6 @@ func (dd *msgpipelineDelivery) Body(header textproto.Header, body buffer.Buffer)
|
|||
|
||||
for _, delivery := range dd.deliveries {
|
||||
if err := delivery.Body(header, body); err != nil {
|
||||
dd.log.Debugf("delivery.Body failure, Delivery object = %T: %v", delivery, err)
|
||||
return err
|
||||
}
|
||||
dd.log.Debugf("delivery.Body ok, Delivery object = %T", delivery)
|
||||
|
@ -351,12 +347,10 @@ func (dd *msgpipelineDelivery) BodyNonAtomic(c module.StatusCollector, header te
|
|||
}
|
||||
|
||||
if err := delivery.Body(header, body); err != nil {
|
||||
dd.log.Debugf("delivery.Body failure, Delivery object = %T: %v", delivery, err)
|
||||
for _, rcpt := range delivery.recipients {
|
||||
c.SetStatus(rcpt, err)
|
||||
}
|
||||
}
|
||||
dd.log.Debugf("delivery.Body ok, Delivery object = %T", delivery)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -365,11 +359,9 @@ func (dd msgpipelineDelivery) Commit() error {
|
|||
|
||||
for _, delivery := range dd.deliveries {
|
||||
if err := delivery.Commit(); err != nil {
|
||||
dd.log.Debugf("delivery.Commit failure, Delivery object = %T: %v", delivery, err)
|
||||
// No point in Committing remaining deliveries, everything is broken already.
|
||||
return err
|
||||
}
|
||||
dd.log.Debugf("delivery.Commit ok, Delivery object = %T", delivery)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
@ -398,7 +390,6 @@ func (dd msgpipelineDelivery) Abort() error {
|
|||
lastErr = err
|
||||
// Continue anyway and try to Abort all remaining delivery objects.
|
||||
}
|
||||
dd.log.Debugf("delivery.Abort ok, Delivery object = %T", delivery)
|
||||
}
|
||||
dd.log.Debugf("delivery aborted")
|
||||
return lastErr
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue