Skip to content

Commit

Permalink
_exception stack dump on verbose, bench fix
Browse files Browse the repository at this point in the history
  • Loading branch information
sdolard committed Dec 24, 2011
1 parent 6819c3c commit edb6a37
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 18 deletions.
28 changes: 14 additions & 14 deletions lib/log-to-file.js
Expand Up @@ -132,7 +132,7 @@ var LogToFile = function (config){ // ctor
this._eexception({ this._eexception({
code: 'EEMPTYFILENAME', code: 'EEMPTYFILENAME',
message: 'fileName config is not set' message: 'fileName config is not set'
},'ctor'); });
return; return;
} }


Expand All @@ -141,7 +141,7 @@ var LogToFile = function (config){ // ctor
this._eexception({ this._eexception({
code: 'EEMPTYDIRECTORY', code: 'EEMPTYDIRECTORY',
message: 'directory config is not set' message: 'directory config is not set'
},'ctor'); });
return; return;
} }
this.directory = path.resolve(config.directory); this.directory = path.resolve(config.directory);
Expand All @@ -150,7 +150,7 @@ var LogToFile = function (config){ // ctor
this._eexception({ this._eexception({
code: 'EDIRNOTFOUND', code: 'EDIRNOTFOUND',
message: 'Directory not found: "' + this.directory + '"' message: 'Directory not found: "' + this.directory + '"'
}, 'ctor'); });
return; return;
} }
this.filePath = path.normalize(this.directory + '/' + this.fileName); this.filePath = path.normalize(this.directory + '/' + this.fileName);
Expand Down Expand Up @@ -202,7 +202,7 @@ LogToFile.prototype._createWriteStream = function(delay) {


fs.stat(this.filePath, function(err, stats) { fs.stat(this.filePath, function(err, stats) {
if (err && err.code !== 'ENOENT') { if (err && err.code !== 'ENOENT') {
me._eexception(err, '_createWriteStream fs.stat'); me._eexception(err);
return; return;
} }
me._writtenSize = stats ? stats.size : 0; me._writtenSize = stats ? stats.size : 0;
Expand All @@ -214,7 +214,7 @@ LogToFile.prototype._createWriteStream = function(delay) {
flags: 'a' flags: 'a'
}); });
me._writableStream.on('error', function(err, fd) { me._writableStream.on('error', function(err, fd) {
me._eexception(err, '_createWriteStream _writableStream on error'); me._eexception(err);
}); });


// Emitted when the underlying file descriptor has been closed. // Emitted when the underlying file descriptor has been closed.
Expand Down Expand Up @@ -328,7 +328,7 @@ LogToFile.prototype._doFileRotation = function() {


fs.readdir(dirname, function(err, files) { fs.readdir(dirname, function(err, files) {
if (err) { if (err) {
me._eexception(err, "_doFileRotation fs.readdir"); me._eexception(err);
return; return;
} }
var var
Expand Down Expand Up @@ -367,7 +367,7 @@ LogToFile.prototype._doFileRotation = function() {
if (me.maxBackupFileNumber === 0) { if (me.maxBackupFileNumber === 0) {
fs.unlink(me.filePath, function(err) { fs.unlink(me.filePath, function(err) {
if (err) { if (err) {
me._eexception(err, "_doFileRotation fs.unlink"); me._eexception(err);
return; return;
} }
// create new stream and write now. // create new stream and write now.
Expand All @@ -376,7 +376,7 @@ LogToFile.prototype._doFileRotation = function() {
} else { } else {
fs.rename(me.filePath, filePath, function(err) { fs.rename(me.filePath, filePath, function(err) {
if (err) { if (err) {
me._eexception(err, "_doFileRotation fs.rename"); me._eexception(err);
return; return;
} }
me._eemit(E_BACKUPED, oldFilePath, filePath); me._eemit(E_BACKUPED, oldFilePath, filePath);
Expand All @@ -397,7 +397,7 @@ LogToFile.prototype._doFileRotation = function() {
if(file.fileIndex >= me.maxBackupFileNumber) { if(file.fileIndex >= me.maxBackupFileNumber) {
fs.unlink(file.oldFileName, function(err) { fs.unlink(file.oldFileName, function(err) {
if (err) { if (err) {
me._eexception(err, "_doFileRotation fs.ulink"); me._eexception(err);
return; return;
} }
if (i < results.length) { if (i < results.length) {
Expand All @@ -410,7 +410,7 @@ LogToFile.prototype._doFileRotation = function() {
} else { } else {
fs.rename(file.oldFileName, file.newFileName, function(err) { fs.rename(file.oldFileName, file.newFileName, function(err) {
if (err) { if (err) {
me._eexception(err, "_doFileRotation fs.rename"); me._eexception(err);
return; return;
} }
if (i < results.length) { if (i < results.length) {
Expand Down Expand Up @@ -472,14 +472,14 @@ LogToFile.prototype.log = function() {
/** /**
* @private * @private
*/ */
LogToFile.prototype._eexception = function(exception, more) { LogToFile.prototype._eexception = function(exception) {
var var
error;

this.log('%s: "%s" (%s)', exception.code, exception.message, more);
error = new Error(exception.message); error = new Error(exception.message);
error.code = exception.code; error.code = exception.code;
this.emit(E_ERROR, error); this.emit(E_ERROR, error);
if (this.verbose && typeof error.stack === 'string') {
console.log(error.stack);
}
}; };


/** /**
Expand Down
5 changes: 1 addition & 4 deletions test/log-to-file-bench.js
Expand Up @@ -122,9 +122,6 @@ function runTest() {
log.gzipBackupFile); log.gzipBackupFile);
bi++; bi++;
log.on('writting', function(fileName){ log.on('writting', function(fileName){
if (writtingEventCount === 0) {
start = Date.now();
}
writtingEventCount ++; writtingEventCount ++;
}); });


Expand All @@ -151,11 +148,11 @@ function runTest() {
console.log(err); console.log(err);
}); });



for (i = 0; i < elements; i++) { for (i = 0; i < elements; i++) {
log.write(dataTest); log.write(dataTest);
size += dataTest.length; size += dataTest.length;
} }
start = Date.now();
} }




Expand Down

0 comments on commit edb6a37

Please sign in to comment.