Skip to content

Commit

Permalink
[fix] Allow multiple streams as @jcrugzz suggested
Browse files Browse the repository at this point in the history
  • Loading branch information
3rd-Eden committed May 29, 2014
1 parent a820d40 commit 86fb8db
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,12 @@ function factory(name, options) {
options.ansi = options.colors ? kuler(name, options.color) : name;
options.stream = options.stream || stream;

//
// Allow multiple streams, so make sure it's an array which makes iteration
// easier.
//
if (!Array.isArray(options.stream)) options.stream = [options.stream];

//
// Add the namespace an re-calculate the max-length of the namespace so we can
// have a consistent indentation.
Expand Down Expand Up @@ -118,11 +124,16 @@ function factory(name, options) {
line
].join('');

options.stream.write(
util.format.apply(this, [line].concat(
//
// Use util.format so we can follow the same API as console.log.
//
line = util.format.apply(this, [line].concat(
Array.prototype.slice.call(arguments, 1)
)
) + '\n');
)) + '\n';

options.stream.forEach(function each(stream) {
stream.write(line);
});

//
// Update the previous call with the current time.
Expand Down

0 comments on commit 86fb8db

Please sign in to comment.