Skip to content

Commit

Permalink
[fix] shallow clone the container options in case we pass in a intsan…
Browse files Browse the repository at this point in the history
…tiated prototypal object
  • Loading branch information
jcrugzz committed Sep 15, 2014
1 parent d65753d commit 08fccc8
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lib/winston/container.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
*/

var common = require('./common'),
winston = require('../winston');
winston = require('../winston'),
extend = require('util')._extend;

//
// ### function Container (options)
Expand Down Expand Up @@ -36,9 +37,19 @@ var Container = exports.Container = function (options) {
// an instance does not exist, one is created.
//
Container.prototype.get = Container.prototype.add = function (id, options) {
var existing;
if (!this.loggers[id]) {
options = common.clone(options || this.options || this.default);
options.transports = options.transports || this.options.transports || [];
//
// Remark: Simple shallow clone for configuration options in case we pass in
// instantiated protoypal objects
//
options = extend({}, options || this.options || this.default);
existing = options.transports || this.options.transports;
//
// Remark: Make sure if we have an array of transports we slice it to make copies
// of those references.
//
options.transports = existing ? existing.slice() : [];

if (options.transports.length === 0 && (!options || !options['console'])) {
options.transports.push(this.default.transports[0]);
Expand Down

0 comments on commit 08fccc8

Please sign in to comment.