Permalink
Browse files

No more event name export

  • Loading branch information...
1 parent c4e7331 commit 2e54f63882028dfe87bcb30c395ed22bffeefa22 @sdolard committed Mar 29, 2012
Showing with 13 additions and 24 deletions.
  1. +13 −24 lib/logtofile.js
View
@@ -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,25 +50,25 @@ 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;
}
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;

0 comments on commit 2e54f63

Please sign in to comment.