From 548cc9000ddd2a949142226f3d28fb4a89c43f25 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Pavel=20Lobodinsky=CC=81?= Date: Tue, 9 Jul 2013 16:07:38 +0200 Subject: [PATCH] Do not add meta into the email body if the object is empty (has not properties) --- lib/winston-mail.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/winston-mail.js b/lib/winston-mail.js index ba1d9d9..e86a356 100644 --- a/lib/winston-mail.js +++ b/lib/winston-mail.js @@ -71,10 +71,11 @@ Mail.prototype.log = function (level, msg, meta, callback) { var self = this; if (this.silent) return callback(null, true); - if (meta) // add some pretty printing - meta = util.inspect(meta, null, 5) + var body = msg; - var body = meta ? msg + "\n\n" + meta : msg; + // add meta info into the body if not empty + if (meta !== null && meta !== undefined && (typeof meta !== 'object' || Object.keys(meta).length > 0)) + body += "\n\n" + util.inspect(meta, {depth: 5}); // add some pretty printing var message = email.message.create({ from: this.from,