Skip to content

Commit

Permalink
Fix: Missing defaultMeta in log entry while using Profiler
Browse files Browse the repository at this point in the history
  • Loading branch information
HonzaMac committed Jun 17, 2021
1 parent 2625f60 commit 584111e
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
8 changes: 8 additions & 0 deletions lib/winston/profiler.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,15 @@ module.exports = class Profiler {
const info = typeof args[args.length - 1] === 'object' ? args.pop() : {};
info.level = info.level || 'info';
info.durationMs = (Date.now()) - this.start;
this._addDefaultMeta(info);

return this.logger.write(info);
}

_addDefaultMeta(msg) {
if (this.logger.defaultMeta) {
Object.assign(msg, this.logger.defaultMeta);
}
}

};
3 changes: 2 additions & 1 deletion test/helpers/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,10 @@ var helpers = exports;
* @param {function} write Write function for the specified stream
* @returns {Logger} A winston.Logger instance
*/
helpers.createLogger = function (write, format) {
helpers.createLogger = function (write, format, defaultMeta) {
return winston.createLogger({
format,
defaultMeta,
transports: [
mockTransport.createMockTransport(write)
]
Expand Down
3 changes: 2 additions & 1 deletion test/logger.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -905,9 +905,10 @@ describe('Logger (profile, startTimer)', function (done) {
assume(info.level).equals('info');
assume(info.durationMs).is.a('number');
assume(info.message).equals('testing1');
assume(info.service).equals('your-service-name');
assume(info[MESSAGE]).is.a('string');
done();
});
}, null, { service: 'your-service-name' });

var timer = logger.startTimer();
setTimeout(function () {
Expand Down

0 comments on commit 584111e

Please sign in to comment.