Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Invocation method pattern fixes

  • Loading branch information...
commit 6819c3c20e179a5479b23114288e17c959c2c0df 1 parent e9f25b5
@sdolard authored
Showing with 25 additions and 26 deletions.
  1. +25 −26 lib/log-to-file.js
View
51 lib/log-to-file.js
@@ -56,7 +56,7 @@ function onTimeout(logFile, origin) {
if (logFile._writtenSize < logFile.fileMaxSize) {
var buffer = logFile._buffers.shift();
if (!buffer) {
- logFile._eemit.call(logFile, E_WRITTEN, logFile.filePath);
+ logFile._eemit(E_WRITTEN, logFile.filePath);
logFile._waitDrain = false; // No more buffer to write, timer can restart
return;
}
@@ -64,15 +64,15 @@ function onTimeout(logFile, origin) {
logFile._writableStream.write(buffer.b.slice(0, buffer.usedBytes));
if (!logFile._waitDrain) {
// If it's first time we start to write, we emit this event
- logFile._eemit.call(logFile, E_WRITTING, logFile.filePath);
+ logFile._eemit(E_WRITTING, logFile.filePath);
logFile._waitDrain = true; // Timer has not to run
}
- logFile._eemit.call(logFile, E_WRITE, logFile.filePath);
+ logFile._eemit(E_WRITE, logFile.filePath);
logFile._writtenSize += buffer.usedBytes;
return;
}
if(logFile._writtenSize !== 0 && logFile._buffers.length === 0) {
- logFile._eemit.call(logFile, E_WRITTEN, logFile.filePath);
+ logFile._eemit(E_WRITTEN, logFile.filePath);
}
logFile._rotationPending = true;
logFile._writableStream.destroySoon(); // this will flush before then close
@@ -202,7 +202,7 @@ LogToFile.prototype._createWriteStream = function(delay) {
fs.stat(this.filePath, function(err, stats) {
if (err && err.code !== 'ENOENT') {
- me._eexception.call(me, err, '_createWriteStream fs.stat');
+ me._eexception(err, '_createWriteStream fs.stat');
return;
}
me._writtenSize = stats ? stats.size : 0;
@@ -214,14 +214,14 @@ LogToFile.prototype._createWriteStream = function(delay) {
flags: 'a'
});
me._writableStream.on('error', function(err, fd) {
- me._eexception.call(me, err, '_createWriteStream _writableStream on error');
+ me._eexception(err, '_createWriteStream _writableStream on error');
});
// Emitted when the underlying file descriptor has been closed.
me._writableStream.on('close', function() {
if (me._rotationPending) {
delete me._writableStream;
- me._doFileRotation.call(me);
+ me._doFileRotation();
}
});
@@ -230,8 +230,8 @@ LogToFile.prototype._createWriteStream = function(delay) {
onTimeout(me, 'drain'); // we write next buffer, if there is
});
- me.log('me._restartTimeout.call(me, delay): %d', delay);
- me._restartTimeout.call(me, delay);
+ me.log('me._restartTimeout(delay): %d', delay);
+ me._restartTimeout(delay);
});
};
@@ -241,17 +241,17 @@ LogToFile.prototype._createWriteStream = function(delay) {
function write(logFile, string) {
var
stringLength = Buffer.byteLength(string),
- buffer = logFile._getBuffer.call(logFile);
+ buffer = logFile._getBuffer();
// Enought place in current buffer?
if (buffer.usedBytes + stringLength > logFile.bufferSize) {
- buffer = logFile._addBuffer.call(logFile);
+ buffer = logFile._addBuffer();
}
buffer.b.write(string, buffer.usedBytes);
buffer.usedBytes += stringLength;
- logFile._restartTimeout.call(logFile);
+ logFile._restartTimeout();
}
/**
@@ -328,7 +328,7 @@ LogToFile.prototype._doFileRotation = function() {
fs.readdir(dirname, function(err, files) {
if (err) {
- me._eexception.call(me, err, "_doFileRotation fs.readdir");
+ me._eexception(err, "_doFileRotation fs.readdir");
return;
}
var
@@ -343,18 +343,18 @@ LogToFile.prototype._doFileRotation = function() {
compressFile = function(filePath) {
var
gzippedFilePath = filePath + '.gz';
- me._eemit.call(me, E_GZIPPING, filePath, gzippedFilePath);
+ me._eemit(E_GZIPPING, filePath, gzippedFilePath);
me.log('gzipping %s...', filePath);
compressReadStream = fs.createReadStream(filePath);
compressWriteStream = fs.createWriteStream(gzippedFilePath);
compressWriteStream.on('close', function() {
- me._eemit.call(me, E_GZIPPED, filePath, gzippedFilePath);
+ me._eemit(E_GZIPPED, filePath, gzippedFilePath);
me.log('"%s" compression done.', filePath);
fs.unlink(filePath, function() {
- me.log("me._createWriteStream.call(me, 1);");
+ me.log("me._createWriteStream(1);");
// create new stream and write now.
- me._createWriteStream.call(me, 1);
+ me._createWriteStream(1);
});
});
gzip = zlib.createGzip({
@@ -367,24 +367,24 @@ LogToFile.prototype._doFileRotation = function() {
if (me.maxBackupFileNumber === 0) {
fs.unlink(me.filePath, function(err) {
if (err) {
- me._eexception.call(me, err, "_doFileRotation fs.unlink");
+ me._eexception(err, "_doFileRotation fs.unlink");
return;
}
// create new stream and write now.
- me._createWriteStream.call(me, 1);
+ me._createWriteStream(1);
});
} else {
fs.rename(me.filePath, filePath, function(err) {
if (err) {
- me._eexception.call(me, err, "_doFileRotation fs.rename");
+ me._eexception(err, "_doFileRotation fs.rename");
return;
}
- me._eemit.call(me, E_BACKUPED, oldFilePath, filePath);
+ me._eemit(E_BACKUPED, oldFilePath, filePath);
if (me.gzipBackupFile) {
compressFile(filePath);
} else {
// create new stream and write now.
- me._createWriteStream.call(me, 1);
+ me._createWriteStream(1);
}
});
@@ -397,7 +397,7 @@ LogToFile.prototype._doFileRotation = function() {
if(file.fileIndex >= me.maxBackupFileNumber) {
fs.unlink(file.oldFileName, function(err) {
if (err) {
- me._eexception.call(me, err, "_doFileRotation fs.ulink");
+ me._eexception(err, "_doFileRotation fs.ulink");
return;
}
if (i < results.length) {
@@ -410,7 +410,7 @@ LogToFile.prototype._doFileRotation = function() {
} else {
fs.rename(file.oldFileName, file.newFileName, function(err) {
if (err) {
- me._eexception.call(me, err, "_doFileRotation fs.rename");
+ me._eexception(err, "_doFileRotation fs.rename");
return;
}
if (i < results.length) {
@@ -495,8 +495,7 @@ LogToFile.prototype._eemit = function(event){
break;
default:
throw new Error('LogToFile.prototype._eemit: argument(s) missing');
- }
-
+ }
};
Please sign in to comment.
Something went wrong with that request. Please try again.