Permalink
Browse files

Path fix for Windows

  • Loading branch information...
1 parent 075a2b1 commit 26e721fc4d9aef1ccf2a58104f2c33d8785fd28d @sdolard committed Nov 18, 2011
Showing with 30 additions and 13 deletions.
  1. +24 −3 README.md
  2. +4 −4 lib/log-to-file.js
  3. +2 −6 test/log-to-file-bench.js
View
27 README.md
@@ -90,7 +90,7 @@ Just run test/run_test.js
Just run test/log-to-file-bench.js
```
-Bench on my MacBook Pro (OS X 10.6.8, 2.53GHz Intel Core 2 Duo, 7200 HDD) with node 0.6.0:
+Bench on my MacBook Pro OS X 10.6.8, 2.53GHz Intel Core 2 Duo (P8700), 7200 HDD with node 0.6.1:
Running bench 0. fileMaxSize: 5.00MB, maxBackupFileNumber: 0, gzipBackupFile: 0
................Total:1.00GB in 12704ms: 80.60MB/s
Running bench 1. fileMaxSize: 5.00MB, maxBackupFileNumber: 0, gzipBackupFile: 1
@@ -107,11 +107,32 @@ Running bench 6. fileMaxSize: 10.00MB, maxBackupFileNumber: 10, gzipBackupFile:
................Total:1.00GB in 10976ms: 93.29MB/s
Running bench 7. fileMaxSize: 10.00MB, maxBackupFileNumber: 10, gzipBackupFile: 1
................Total:1.00GB in 24251ms: 42.23MB/s
-Running bench 8. fileMaxSize: 10.00MB, maxBackupFileNumber: 10, gzipBackupFile: 1
-................Total:1.00GB in 24677ms: 41.50MB/s
All done
```
+```
+Bench on my Ubuntu 11.10 desktop, 3GHz Intel Core 2 Duo CPU (E8400), 7200 HDD with node 0.6.1:
+Running bench 0. fileMaxSize: 5.00MB, maxBackupFileNumber: 0, gzipBackupFile: 0
+................Total:1.00GB in 2447ms: 418.47MB/s
+Running bench 1. fileMaxSize: 5.00MB, maxBackupFileNumber: 0, gzipBackupFile: 1
+................Total:1.00GB in 2453ms: 417.45MB/s
+Running bench 2. fileMaxSize: 5.00MB, maxBackupFileNumber: 5, gzipBackupFile: 0
+................Total:1.00GB in 2578ms: 397.21MB/s
+Running bench 3. fileMaxSize: 5.00MB, maxBackupFileNumber: 5, gzipBackupFile: 1
+................Total:1.00GB in 9936ms: 103.06MB/s
+Running bench 4. fileMaxSize: 5.00MB, maxBackupFileNumber: 10, gzipBackupFile: 0
+................Total:1.00GB in 13173ms: 77.73MB/s
+Running bench 5. fileMaxSize: 5.00MB, maxBackupFileNumber: 10, gzipBackupFile: 1
+................Total:1.00GB in 9564ms: 107.07MB/s
+Running bench 6. fileMaxSize: 10.00MB, maxBackupFileNumber: 10, gzipBackupFile: 0
+................Total:1.00GB in 13550ms: 75.57MB/s
+Running bench 7. fileMaxSize: 10.00MB, maxBackupFileNumber: 10, gzipBackupFile: 1
+................Total:1.00GB in 9151ms: 111.90MB/s
+All done
+
+```
+
+
## License
node-log-to-file is licensed under the MIT license.
View
8 lib/log-to-file.js
@@ -128,7 +128,7 @@ var LogToFile = function (config){ // ctor
message: 'Directory not found: "' + this.directory + '"'
};
}
- this.filePath = this.directory + '/' + this.fileName;
+ this.filePath = path.normalize(this.directory + '/' + this.fileName);
this.writeDelay = Math.max(config.writeDelay || 200, 10); // Buffer is flushed every 200 ms, min 10
this.bufferSize = Math.max(config.bufferSize || 65536, 4096); // Buffer blocks size, min 4096o
this.fileMaxSize = Math.max(config.fileMaxSize || 1024 * 1024 * 5, 1024 * 1024); // 5MB, min 1MB
@@ -298,7 +298,7 @@ LogToFile.prototype._doFileRotation = function() {
oldFilePath = this.filePath,
dirname = path.dirname(this.filePath),
basename = path.basename(this.filePath),
- filePath = dirname + '/' + basename + "."+ formatIndex(0, me._maxBackupFileNumberLength);
+ filePath = path.normalize(dirname + '/' + basename + "."+ formatIndex(0, me._maxBackupFileNumberLength));
fs.readdir(dirname, function(err, files) {
if (err) {
@@ -406,8 +406,8 @@ LogToFile.prototype._doFileRotation = function() {
results.push({
fileIndex: fileIndex,
- oldFileName: dirname + '/' + matches[0],
- newFileName: dirname + '/' + basename + '.' + formatIndex(newFileIndex, me._maxBackupFileNumberLength) + gzipExt
+ oldFileName: path.normalize(dirname + '/' + matches[0]),
+ newFileName: path.normalize(dirname + '/' + basename + '.' + formatIndex(newFileIndex, me._maxBackupFileNumberLength) + gzipExt)
});
}
}
View
8 test/log-to-file-bench.js
@@ -1,4 +1,5 @@
var
+path = require('path'),
util = require('util'),
fs = require('fs'),
logToFile = require('../lib/log-to-file'),
@@ -44,11 +45,6 @@ benchParams = [
fileMaxSize: ONE_M * 10,
maxBackupFileNumber: 10,
gzipBackupFile: true
- },
- {
- fileMaxSize: ONE_M * 10,
- maxBackupFileNumber: 10,
- gzipBackupFile: true
}], bi = 0;
for ( i = 0; i < 1024; ++i) {
@@ -94,7 +90,7 @@ function runTest() {
continue;
}
//console.log('unlink: %s', dirs[i]);
- fs.unlinkSync(__dirname + '/' + dirs[i]);
+ fs.unlinkSync(path.normalize(__dirname + '/' + dirs[i]));
}
console.log('All done');
return;

0 comments on commit 26e721f

Please sign in to comment.