From ac9a7255b79c39047f9736d98fb7aebbf20ea1e9 Mon Sep 17 00:00:00 2001 From: unknown Date: Sun, 4 Feb 2024 20:27:55 +0530 Subject: [PATCH] Issue#232 - timestamp format fix --- lib/winston-mongodb.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/winston-mongodb.js b/lib/winston-mongodb.js index 6acd93a..186cc23 100644 --- a/lib/winston-mongodb.js +++ b/lib/winston-mongodb.js @@ -219,7 +219,11 @@ MongoDB.prototype.log = function (info, cb) { } // eslint-disable-next-line no-control-regex const decolorizeRegex = new RegExp(/\u001b\[[0-9]{1,2}m/g); - const entry = { timestamp: new Date(), level: (this.decolorize) ? info.level.replace(decolorizeRegex, '') : info.level }; + const entry = { + // when format option is used in winston, logform will generate timestamp with specified format. + timestamp: info.timestamp? info.timestamp : new Date(), + level: (this.decolorize) ? info.level.replace(decolorizeRegex, '') : info.level + }; const msg = util.format(info.message, ...(info.splat || [])); entry.message = (this.decolorize) ? msg.replace(decolorizeRegex, '') : msg; // get 'meta' object from info object - as per winston doc: Properties besides level and message are considered as "meta".