Browse Source

Improved logging

Brendan Abolivier 8 years ago
parent
commit
e8e022e5e6
1 changed files with 10 additions and 10 deletions
  1. 10
    10
      server.js

+ 10
- 10
server.js View File

40
     // text entered by the user
40
     // text entered by the user
41
     params.html = pug.renderFile('template.pug', params);
41
     params.html = pug.renderFile('template.pug', params);
42
     
42
     
43
-    log.info('Sending message from ' + content.from);
43
+    log.info('Sending message from ' + params.from);
44
     
44
     
45
     // Send the email to all users
45
     // Send the email to all users
46
     sendMails(params, function(err, infos) {
46
     sendMails(params, function(err, infos) {
76
 function sendMails(params, update, done) {
76
 function sendMails(params, update, done) {
77
     let mails = settings.recipients.map((recipient) => {
77
     let mails = settings.recipients.map((recipient) => {
78
         // Promise for each recipient to send each mail asynchronously
78
         // Promise for each recipient to send each mail asynchronously
79
-        return new Promise((sent) => {            
79
+        return new Promise((sent) => {
80
             params.to = recipient;
80
             params.to = recipient;
81
             // Send the email
81
             // Send the email
82
             transporter.sendMail(params, (err, infos) => {
82
             transporter.sendMail(params, (err, infos) => {
83
-                // Promise callback
84
-                sent();
85
                 if(err) {
83
                 if(err) {
86
-                    return next(err, recipient);
84
+                    return update(err, recipient);
87
                 }
85
                 }
88
-                next(null, infos);
86
+                update(null, infos);
87
+                // Promise callback
88
+                sent();
89
             });
89
             });
90
         });
90
         });
91
     });
91
     });
98
 // infos: infos provided by nodemailer
98
 // infos: infos provided by nodemailer
99
 // return: nothing
99
 // return: nothing
100
 function logStatus(infos) {
100
 function logStatus(infos) {
101
-    if(infos.accepted.length) {
102
-        log.info('Message sent to ' + status.accepted[0]);
101
+    if(infos.accepted.length !== 0) {
102
+        log.info('Message sent to ' + infos.accepted[0]);
103
     }
103
     }
104
-    if(infos.rejected.length) {
105
-        log.info('Message failed to send to ' + status.rejected[0]);
104
+    if(infos.rejected.length !== 0) {
105
+        log.info('Message failed to send to ' + infos.rejected[0]);
106
     }
106
     }
107
 }
107
 }