summaryrefslogtreecommitdiff
path: root/notifications.go
diff options
context:
space:
mode:
authorJan Dittberner <jandd@cacert.org>2017-04-22 20:07:39 +0200
committerJan Dittberner <jandd@cacert.org>2017-04-22 20:07:39 +0200
commit4d23b6a48f26485f6c33d7948970191bd9357471 (patch)
tree5fba7d8226c7c7fcac51827615d69560ab5da21f /notifications.go
parenteec8620e49a79481eed78148a1f4d6279e96b974 (diff)
downloadcacert-boardvoting-4d23b6a48f26485f6c33d7948970191bd9357471.tar.gz
cacert-boardvoting-4d23b6a48f26485f6c33d7948970191bd9357471.tar.xz
cacert-boardvoting-4d23b6a48f26485f6c33d7948970191bd9357471.zip
Switch to more flexible go-logging
This commit switches from loggo to the more flexible go-logging framework. Logs of severity INFO or higher are now written to a separate boardvoting.log file. Errors during execution of mail templates are now logged. A reasoning for the vote result is now logged and put into the mail notification when a decision is closed.
Diffstat (limited to 'notifications.go')
-rw-r--r--notifications.go23
1 files changed, 14 insertions, 9 deletions
diff --git a/notifications.go b/notifications.go
index 5061a2a..02d814d 100644
--- a/notifications.go
+++ b/notifications.go
@@ -34,14 +34,14 @@ type NotificationMail interface {
var NotifyMailChannel = make(chan NotificationMail, 1)
func MailNotifier(quitMailNotifier chan int) {
- logger.Infof("Launched mail notifier")
+ log.Info("Launched mail notifier")
for {
select {
case notification := <-NotifyMailChannel:
content := notification.GetNotificationContent()
mailText, err := buildMail(content.template, content.data)
if err != nil {
- logger.Errorf("building mail failed: %s", err)
+ log.Errorf("building mail failed: %v", err)
continue
}
@@ -58,10 +58,10 @@ func MailNotifier(quitMailNotifier chan int) {
d := gomail.NewDialer(config.MailServer.Host, config.MailServer.Port, "", "")
if err := d.DialAndSend(m); err != nil {
- logger.Errorf("sending mail failed: %s", err)
+ log.Errorf("sending mail failed: %v", err)
}
case <-quitMailNotifier:
- logger.Infof("Ending mail notifier")
+ log.Info("Ending mail notifier")
return
}
}
@@ -75,7 +75,10 @@ func buildMail(templateName string, context interface{}) (mailText *bytes.Buffer
}
mailText = bytes.NewBufferString("")
- t.Execute(mailText, context)
+ if err := t.Execute(mailText, context); err != nil {
+ log.Errorf("Failed to execute template %s with context %+v: %v", templateName, context, err)
+ return nil, err
+ }
return
}
@@ -108,11 +111,12 @@ func (n *decisionReplyBase) getSubject() string {
type notificationClosedDecision struct {
notificationBase
decisionReplyBase
- voteSums VoteSums
+ voteSums VoteSums
+ reasoning string
}
-func NewNotificationClosedDecision(decision *Decision, voteSums *VoteSums) NotificationMail {
- notification := &notificationClosedDecision{voteSums: *voteSums}
+func NewNotificationClosedDecision(decision *Decision, voteSums *VoteSums, reasoning string) NotificationMail {
+ notification := &notificationClosedDecision{voteSums: *voteSums, reasoning: reasoning}
notification.decision = *decision
return notification
}
@@ -123,7 +127,8 @@ func (n *notificationClosedDecision) GetNotificationContent() *notificationConte
data: struct {
*Decision
*VoteSums
- }{&n.decision, &n.voteSums},
+ Reasoning string
+ }{&n.decision, &n.voteSums, n.reasoning},
subject: fmt.Sprintf("Re: %s - %s - finalised", n.decision.Tag, n.decision.Title),
headers: n.decisionReplyBase.getHeaders(),
recipients: []recipientData{n.notificationBase.getRecipient()},