fh-reportingclient
Advanced tools
Comparing version 0.1.1 to 0.2.1
@@ -5,3 +5,7 @@ var request = require('request'); | ||
var crypto = require('crypto'); | ||
var backUpFileStream; | ||
var recoveryFileStream; | ||
exports.Reporting = Reporting; | ||
@@ -92,7 +96,30 @@ | ||
}; | ||
//note backUpFileStream and recoveryFileStream are singletons and are only created once per application lifecycle. | ||
//this is to address the problem of having too many file handles open ticket | ||
Reporting.prototype.saveToFile = function (filepath, msg, cb) { | ||
var stream; | ||
var fileFlags = {flags:'a'}; | ||
if(this.config.backupFiles && filepath === this.config.backupFiles.fileName){ | ||
if(! backUpFileStream){ | ||
backUpFileStream = fs.createWriteStream(filepath,fileFlags); | ||
} | ||
stream = backUpFileStream; | ||
}else if (this.config.recoveryFiles && filepath === this.config.recoveryFiles.fileName){ | ||
if(! recoveryFileStream){ | ||
recoveryFileStream = fs.createWriteStream(filepath,fileFlags); | ||
} | ||
stream = recoveryFileStream; | ||
}else if(filepath){ | ||
//fallback to creating a write stream and destroying it? | ||
var tempStream = fs.createWriteStream(filepath , fileFlags); | ||
tempStream.write(JSON.stringify(msg) + "\n"); | ||
tempStream.destroySoon(); | ||
} | ||
if(stream){ | ||
stream.write(JSON.stringify(msg) + "\n"); | ||
stream.on('error', function (err){ | ||
cb(err); | ||
}); | ||
} | ||
Reporting.prototype.saveToFile = function (filepath, msg, cb) { | ||
var s = fs.createWriteStream(filepath, {flags:'a'}); | ||
s.write(JSON.stringify(msg) + "\n"); | ||
s.destroySoon(); | ||
if (cb) { | ||
@@ -99,0 +126,0 @@ process.nextTick(cb); |
@@ -6,3 +6,3 @@ { | ||
"description": "FH Reporting Client", | ||
"version": "0.1.1", | ||
"version": "0.2.1", | ||
"directories":{ | ||
@@ -9,0 +9,0 @@ "lib": "./lib" |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19
179
32924