From 2e54f63882028dfe87bcb30c395ed22bffeefa22 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9basten=20Dolard?= Date: Thu, 29 Mar 2012 21:16:52 +0200 Subject: [PATCH] No more event name export --- lib/logtofile.js | 37 +++++++++++++------------------------ 1 file changed, 13 insertions(+), 24 deletions(-) diff --git a/lib/logtofile.js b/lib/logtofile.js index 1f1afc4..c28a750 100644 --- a/lib/logtofile.js +++ b/lib/logtofile.js @@ -26,14 +26,7 @@ fs = require('fs'), EventEmitter = require('events').EventEmitter, util = require('util'), zlib = require('zlib'), -DEFAULT_WRITE_DELAY = 200, -E_ERROR = 'error', // event -E_WRITTING = 'writting', // event -E_WRITTEN = 'written', // event -E_WRITE = 'write', // event -E_BACKUPED = 'backuped', // event -E_GZIPPING = 'gzipping', // event -E_GZIPPED = 'gzipped'; // event +DEFAULT_WRITE_DELAY = 200; /** @@ -42,6 +35,9 @@ E_GZIPPED = 'gzipped'; // event * It can be called to in buffer drain context */ function onTimeout(logFile, origin) { + var + buffer; + // Two possible origin // - drain // - timeout @@ -54,9 +50,9 @@ function onTimeout(logFile, origin) { } if (logFile._writtenSize < logFile.fileMaxSize) { - var buffer = logFile._buffers.shift(); + buffer = logFile._buffers.shift(); if (!buffer) { - logFile._eemit(E_WRITTEN, logFile.filePath); + logFile._eemit('written', logFile.filePath); logFile._waitDrain = false; // No more buffer to write, timer can restart return; } @@ -64,15 +60,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(E_WRITTING, logFile.filePath); + logFile._eemit('writting', logFile.filePath); logFile._waitDrain = true; // Timer has not to run } - logFile._eemit(E_WRITE, logFile.filePath); + logFile._eemit('write', logFile.filePath); logFile._writtenSize += buffer.usedBytes; return; } if(logFile._writtenSize !== 0 && logFile._buffers.length === 0) { - logFile._eemit(E_WRITTEN, logFile.filePath); + logFile._eemit('written', logFile.filePath); } logFile._rotationPending = true; logFile._writableStream.destroySoon(); // this will flush before then close @@ -347,12 +343,12 @@ LogToFile.prototype._doFileRotation = function() { compressFile = function(filePath) { var gzippedFilePath = filePath + '.gz'; - me._eemit(E_GZIPPING, filePath, gzippedFilePath); + me._eemit('gzipping', filePath, gzippedFilePath); me.log('gzipping %s...', filePath); compressReadStream = fs.createReadStream(filePath); compressWriteStream = fs.createWriteStream(gzippedFilePath); compressWriteStream.on('close', function() { - me._eemit(E_GZIPPED, filePath, gzippedFilePath); + me._eemit('gzipped', filePath, gzippedFilePath); me.log('"%s" compression done.', filePath); fs.unlink(filePath, function() { me.log("me._createWriteStream(1);"); @@ -383,7 +379,7 @@ LogToFile.prototype._doFileRotation = function() { me._eexception(err); return; } - me._eemit(E_BACKUPED, oldFilePath, filePath); + me._eemit('backuped', oldFilePath, filePath); if (me.gzipBackupFile) { compressFile(filePath); } else { @@ -486,7 +482,7 @@ LogToFile.prototype._eexception = function(exception) { error.code = exception.code; } - this.emit(E_ERROR, error); + this.emit('error', error); if (this.verbose) { console.log(error.stack); } @@ -514,11 +510,4 @@ LogToFile.prototype._eemit = function(event){ * Exports *******************************************************************************/ exports.create = function(config) { return new LogToFile(config); }; -exports.E_ERROR = E_ERROR; -exports.E_WRITTING = E_WRITTING; -exports.E_WRITE = E_WRITE; -exports.E_WRITTEN = E_WRITTEN; -exports.E_BACKUPED = E_BACKUPED; -exports.E_GZIPPING = E_GZIPPING; -exports.E_GZIPPED = E_GZIPPED;