Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

_exception stack dump on verbose, bench fix

  • Loading branch information...
commit edb6a375fad56b68d7b8fb54a9f19e8c570df7aa 1 parent 6819c3c
@sdolard authored
Showing with 15 additions and 18 deletions.
  1. +14 −14 lib/log-to-file.js
  2. +1 −4 test/log-to-file-bench.js
View
28 lib/log-to-file.js
@@ -132,7 +132,7 @@ var LogToFile = function (config){ // ctor
this._eexception({
code: 'EEMPTYFILENAME',
message: 'fileName config is not set'
- },'ctor');
+ });
return;
}
@@ -141,7 +141,7 @@ var LogToFile = function (config){ // ctor
this._eexception({
code: 'EEMPTYDIRECTORY',
message: 'directory config is not set'
- },'ctor');
+ });
return;
}
this.directory = path.resolve(config.directory);
@@ -150,7 +150,7 @@ var LogToFile = function (config){ // ctor
this._eexception({
code: 'EDIRNOTFOUND',
message: 'Directory not found: "' + this.directory + '"'
- }, 'ctor');
+ });
return;
}
this.filePath = path.normalize(this.directory + '/' + this.fileName);
@@ -202,7 +202,7 @@ LogToFile.prototype._createWriteStream = function(delay) {
fs.stat(this.filePath, function(err, stats) {
if (err && err.code !== 'ENOENT') {
- me._eexception(err, '_createWriteStream fs.stat');
+ me._eexception(err);
return;
}
me._writtenSize = stats ? stats.size : 0;
@@ -214,7 +214,7 @@ LogToFile.prototype._createWriteStream = function(delay) {
flags: 'a'
});
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.
@@ -328,7 +328,7 @@ LogToFile.prototype._doFileRotation = function() {
fs.readdir(dirname, function(err, files) {
if (err) {
- me._eexception(err, "_doFileRotation fs.readdir");
+ me._eexception(err);
return;
}
var
@@ -367,7 +367,7 @@ LogToFile.prototype._doFileRotation = function() {
if (me.maxBackupFileNumber === 0) {
fs.unlink(me.filePath, function(err) {
if (err) {
- me._eexception(err, "_doFileRotation fs.unlink");
+ me._eexception(err);
return;
}
// create new stream and write now.
@@ -376,7 +376,7 @@ LogToFile.prototype._doFileRotation = function() {
} else {
fs.rename(me.filePath, filePath, function(err) {
if (err) {
- me._eexception(err, "_doFileRotation fs.rename");
+ me._eexception(err);
return;
}
me._eemit(E_BACKUPED, oldFilePath, filePath);
@@ -397,7 +397,7 @@ LogToFile.prototype._doFileRotation = function() {
if(file.fileIndex >= me.maxBackupFileNumber) {
fs.unlink(file.oldFileName, function(err) {
if (err) {
- me._eexception(err, "_doFileRotation fs.ulink");
+ me._eexception(err);
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(err, "_doFileRotation fs.rename");
+ me._eexception(err);
return;
}
if (i < results.length) {
@@ -472,14 +472,14 @@ LogToFile.prototype.log = function() {
/**
* @private
*/
-LogToFile.prototype._eexception = function(exception, more) {
+LogToFile.prototype._eexception = function(exception) {
var
- error;
-
- this.log('%s: "%s" (%s)', exception.code, exception.message, more);
error = new Error(exception.message);
error.code = exception.code;
this.emit(E_ERROR, error);
+ if (this.verbose && typeof error.stack === 'string') {
+ console.log(error.stack);
+ }
};
/**
View
5 test/log-to-file-bench.js
@@ -122,9 +122,6 @@ function runTest() {
log.gzipBackupFile);
bi++;
log.on('writting', function(fileName){
- if (writtingEventCount === 0) {
- start = Date.now();
- }
writtingEventCount ++;
});
@@ -151,11 +148,11 @@ function runTest() {
console.log(err);
});
-
for (i = 0; i < elements; i++) {
log.write(dataTest);
size += dataTest.length;
}
+ start = Date.now();
}
Please sign in to comment.
Something went wrong with that request. Please try again.