Skip to content

Commit

Permalink
[fix] temporary fix for #150. reverts f246617.
Browse files Browse the repository at this point in the history
  • Loading branch information
chjj committed Jul 2, 2012
1 parent 94c6518 commit ff8fbe7
Showing 1 changed file with 5 additions and 42 deletions.
47 changes: 5 additions & 42 deletions lib/winston/transports/file.js
Expand Up @@ -45,13 +45,6 @@ var File = exports.File = function (options) {
else if (options.stream) {
throwIf('stream', 'filename', 'maxsize');
this._stream = options.stream;

//
// We need to listen for drain events when
// write() returns false. This can make node
// mad at times.
//
this._stream.setMaxListeners(Infinity);
}
else {
throw new Error('Cannot log to file without filename or stream.');
Expand Down Expand Up @@ -118,7 +111,7 @@ File.prototype.log = function (level, msg, meta, callback) {
// with a raw `WriteableStream` instance and we should not perform any
// size restrictions.
//
this._write(output, callback);
this._stream.write(output);
this._lazyDrain();
}
else {
Expand All @@ -127,35 +120,15 @@ File.prototype.log = function (level, msg, meta, callback) {
//
// If there was an error enqueue the message
//
return self._buffer.push([output, callback]);
return self._buffer.push(output);
}

self._write(output, callback);
self._stream.write(output);
self._lazyDrain();
});
}
};

//
// ### function _write (data, cb)
// #### @data {String|Buffer} Data to write to the instance's stream.
// #### @cb {function} Continuation to respond to when complete.
// Write to the stream, ensure execution of a callback on completion.
//
File.prototype._write = function(data, callback) {
// If this is a file write stream, we could use the builtin
// callback functionality, however, the stream is not guaranteed
// to be an fs.WriteStream.
var ret = this._stream.write(data);
if (!callback) return;
if (ret === false) {
return this._stream.once('drain', function() {
callback(null, true);
});
}
callback(null, true);
};

//
// ### function query (options, callback)
// #### @options {Object} Loggly-like query options for this instance.
Expand Down Expand Up @@ -415,12 +388,9 @@ File.prototype.flush = function () {
// Iterate over the `_buffer` of enqueued messaged
// and then write them to the newly created stream.
//
this._buffer.forEach(function (item) {
var str = item[0],
callback = item[1];

this._buffer.forEach(function (str) {
process.nextTick(function () {
self._write(str, callback);
self._stream.write(str);
self._size += str.length;
});
});
Expand Down Expand Up @@ -467,13 +437,6 @@ File.prototype._createStream = function () {
self.filename = target;
self._stream = fs.createWriteStream(fullname, self.options);

//
// We need to listen for drain events when
// write() returns false. This can make node
// mad at times.
//
self._stream.setMaxListeners(Infinity);

//
// When the current stream has finished flushing
// then we can be sure we have finished opening
Expand Down

0 comments on commit ff8fbe7

Please sign in to comment.