Skip to content

Commit

Permalink
[fix] do proper streams2 detection so we dont cause possible slowdown…
Browse files Browse the repository at this point in the history
…s when writing to file fixes #296
  • Loading branch information
jcrugzz committed Nov 4, 2014
1 parent 498b216 commit 5c4bd41
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions lib/winston/transports/file.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ var events = require('events'),
colors = require('colors'),
common = require('../common'),
Transport = require('./transport').Transport,
isWritable = require('isStream').isWritable,
Stream = require('stream').Stream;

//
Expand Down Expand Up @@ -53,7 +54,7 @@ var File = exports.File = function (options) {
else if (options.stream) {
throwIf('stream', 'filename', 'maxsize');
this._stream = options.stream;

this._isStreams2 = isWritable(this._stream);
//
// We need to listen for drain events when
// write() returns false. This can make node
Expand Down Expand Up @@ -168,7 +169,7 @@ File.prototype.log = function (level, msg, meta, callback) {
File.prototype._write = function(data, callback) {
if (this._isStreams2) {
this._stream.write(data);
return process.nextTick(function () {
return callback && process.nextTick(function () {
callback(null, true);
});
}
Expand All @@ -183,7 +184,9 @@ File.prototype._write = function(data, callback) {
callback(null, true);
});
}
callback(null, true);
process.nextTick(function () {
callback(null, true);
});
};

//
Expand Down Expand Up @@ -438,7 +441,7 @@ File.prototype._createStream = function () {
self._size = size;
self.filename = target;
self._stream = fs.createWriteStream(fullname, self.options);

self._isStreams2 = isWritable(self._stream);
//
// We need to listen for drain events when
// write() returns false. This can make node
Expand Down

1 comment on commit 5c4bd41

@mneil
Copy link
Contributor

@mneil mneil commented on 5c4bd41 Nov 4, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Incorrect case for isstream modules breaking on Ubuntu builds.

isWritable = require('isStream').isWritable,

should be

isWritable = require('isstream').isWritable,

Please sign in to comment.