diff --git a/lib/winston/transports/file.js b/lib/winston/transports/file.js index 6a26bc8f3..d992af868 100644 --- a/lib/winston/transports/file.js +++ b/lib/winston/transports/file.js @@ -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; // @@ -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 @@ -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); }); } @@ -183,7 +184,9 @@ File.prototype._write = function(data, callback) { callback(null, true); }); } - callback(null, true); + process.nextTick(function () { + callback(null, true); + }); }; // @@ -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