Skip to content

Commit

Permalink
Date instances logging support; fix for #105
Browse files Browse the repository at this point in the history
  • Loading branch information
yurijmikhalevich committed Sep 25, 2017
1 parent bb85d52 commit 5cb0d75
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/helpers.js
Expand Up @@ -65,7 +65,7 @@ function makeObjectNonCircular(node, opt_parents) {
continue;
}
let value = node[key];
if (typeof value === 'object' && !(value instanceof ObjectID)) {
if (typeof value === 'object' && !(value instanceof ObjectID) && !(value instanceof Date)) {
if (opt_parents.indexOf(value) === -1) {
copy[key] = makeObjectNonCircular(value, opt_parents);
} else {
Expand Down
22 changes: 22 additions & 0 deletions test/helpers-test.js
@@ -0,0 +1,22 @@
/**
* @module 'helpers-test'
* @fileoverview Tests for winston-mongodb internal helpers methods
* @license MIT
* @author 0@39.yt (Yurij Mikhalevich)
*/
'use strict';
const vows = require('vows');
const assert = require('assert');
const helpers = require('../lib/helpers');

const originalData = {customDate: new Date()};

vows.describe('winston-mongodb-helpers').addBatch({
'prepareMetaData': {
topic: helpers.prepareMetaData(originalData),
'should preserve Date instances': function(preparedData) {
assert.isTrue(preparedData.customDate instanceof Date);
assert.equal(+preparedData.customDate, +originalData.customDate);
}
}
}).export(module);

0 comments on commit 5cb0d75

Please sign in to comment.