aboutsummaryrefslogtreecommitdiffstats
path: root/vnfmarket/src/main/webapp/vnfmarket/node_modules/log4js/lib/streams
diff options
context:
space:
mode:
Diffstat (limited to 'vnfmarket/src/main/webapp/vnfmarket/node_modules/log4js/lib/streams')
-rw-r--r--vnfmarket/src/main/webapp/vnfmarket/node_modules/log4js/lib/streams/BaseRollingFileStream.js94
-rw-r--r--vnfmarket/src/main/webapp/vnfmarket/node_modules/log4js/lib/streams/DateRollingFileStream.js91
-rw-r--r--vnfmarket/src/main/webapp/vnfmarket/node_modules/log4js/lib/streams/RollingFileStream.js117
-rw-r--r--vnfmarket/src/main/webapp/vnfmarket/node_modules/log4js/lib/streams/index.js3
4 files changed, 305 insertions, 0 deletions
diff --git a/vnfmarket/src/main/webapp/vnfmarket/node_modules/log4js/lib/streams/BaseRollingFileStream.js b/vnfmarket/src/main/webapp/vnfmarket/node_modules/log4js/lib/streams/BaseRollingFileStream.js
new file mode 100644
index 00000000..9c441ad9
--- /dev/null
+++ b/vnfmarket/src/main/webapp/vnfmarket/node_modules/log4js/lib/streams/BaseRollingFileStream.js
@@ -0,0 +1,94 @@
+"use strict";
+var fs = require('fs')
+, stream
+, debug = require('../debug')('BaseRollingFileStream')
+, util = require('util')
+, semver = require('semver');
+
+if (semver.satisfies(process.version, '>=0.10.0')) {
+ stream = require('stream');
+} else {
+ stream = require('readable-stream');
+}
+
+module.exports = BaseRollingFileStream;
+
+function BaseRollingFileStream(filename, options) {
+ debug("In BaseRollingFileStream");
+ this.filename = filename;
+ this.options = options || {};
+ this.options.encoding = this.options.encoding || 'utf8';
+ this.options.mode = this.options.mode || parseInt('0644', 8);
+ this.options.flags = this.options.flags || 'a';
+
+ this.currentSize = 0;
+
+ function currentFileSize(file) {
+ var fileSize = 0;
+ try {
+ fileSize = fs.statSync(file).size;
+ } catch (e) {
+ // file does not exist
+ }
+ return fileSize;
+ }
+
+ function throwErrorIfArgumentsAreNotValid() {
+ if (!filename) {
+ throw new Error("You must specify a filename");
+ }
+ }
+
+ throwErrorIfArgumentsAreNotValid();
+ debug("Calling BaseRollingFileStream.super");
+ BaseRollingFileStream.super_.call(this);
+ this.openTheStream();
+ this.currentSize = currentFileSize(this.filename);
+}
+util.inherits(BaseRollingFileStream, stream.Writable);
+
+BaseRollingFileStream.prototype._write = function(chunk, encoding, callback) {
+ var that = this;
+ function writeTheChunk() {
+ debug("writing the chunk to the underlying stream");
+ that.currentSize += chunk.length;
+ try {
+ that.theStream.write(chunk, encoding, callback);
+ }
+ catch (err){
+ debug(err);
+ callback();
+ }
+ }
+
+ debug("in _write");
+
+ if (this.shouldRoll()) {
+ this.currentSize = 0;
+ this.roll(this.filename, writeTheChunk);
+ } else {
+ writeTheChunk();
+ }
+};
+
+BaseRollingFileStream.prototype.openTheStream = function(cb) {
+ debug("opening the underlying stream");
+ this.theStream = fs.createWriteStream(this.filename, this.options);
+ if (cb) {
+ this.theStream.on("open", cb);
+ }
+};
+
+BaseRollingFileStream.prototype.closeTheStream = function(cb) {
+ debug("closing the underlying stream");
+ this.theStream.end(cb);
+};
+
+BaseRollingFileStream.prototype.shouldRoll = function() {
+ return false; // default behaviour is never to roll
+};
+
+BaseRollingFileStream.prototype.roll = function(filename, callback) {
+ callback(); // default behaviour is not to do anything
+};
+
diff --git a/vnfmarket/src/main/webapp/vnfmarket/node_modules/log4js/lib/streams/DateRollingFileStream.js b/vnfmarket/src/main/webapp/vnfmarket/node_modules/log4js/lib/streams/DateRollingFileStream.js
new file mode 100644
index 00000000..5ef2081f
--- /dev/null
+++ b/vnfmarket/src/main/webapp/vnfmarket/node_modules/log4js/lib/streams/DateRollingFileStream.js
@@ -0,0 +1,91 @@
+"use strict";
+var BaseRollingFileStream = require('./BaseRollingFileStream')
+, debug = require('../debug')('DateRollingFileStream')
+, format = require('../date_format')
+, fs = require('fs')
+, util = require('util');
+
+module.exports = DateRollingFileStream;
+
+function findTimestampFromFileIfExists(filename, now) {
+ return fs.existsSync(filename) ? fs.statSync(filename).mtime : new Date(now());
+}
+
+function DateRollingFileStream(filename, pattern, options, now) {
+ debug("Now is " + now);
+ if (pattern && typeof(pattern) === 'object') {
+ now = options;
+ options = pattern;
+ pattern = null;
+ }
+ this.pattern = pattern || '.yyyy-MM-dd';
+ this.now = now || Date.now;
+ this.lastTimeWeWroteSomething = format.asString(
+ this.pattern,
+ findTimestampFromFileIfExists(filename, this.now)
+ );
+
+ this.baseFilename = filename;
+ this.alwaysIncludePattern = false;
+
+ if (options) {
+ if (options.alwaysIncludePattern) {
+ this.alwaysIncludePattern = true;
+ filename = this.baseFilename + this.lastTimeWeWroteSomething;
+ }
+ delete options.alwaysIncludePattern;
+ if (Object.keys(options).length === 0) {
+ options = null;
+ }
+ }
+ debug("this.now is " + this.now + ", now is " + now);
+
+ DateRollingFileStream.super_.call(this, filename, options);
+}
+util.inherits(DateRollingFileStream, BaseRollingFileStream);
+
+DateRollingFileStream.prototype.shouldRoll = function() {
+ var lastTime = this.lastTimeWeWroteSomething,
+ thisTime = format.asString(this.pattern, new Date(this.now()));
+
+ debug("DateRollingFileStream.shouldRoll with now = " +
+ this.now() + ", thisTime = " + thisTime + ", lastTime = " + lastTime);
+
+ this.lastTimeWeWroteSomething = thisTime;
+ this.previousTime = lastTime;
+
+ return thisTime !== lastTime;
+};
+
+DateRollingFileStream.prototype.roll = function(filename, callback) {
+ var that = this;
+
+ debug("Starting roll");
+
+ if (this.alwaysIncludePattern) {
+ this.filename = this.baseFilename + this.lastTimeWeWroteSomething;
+ this.closeTheStream(this.openTheStream.bind(this, callback));
+ } else {
+ var newFilename = this.baseFilename + this.previousTime;
+ this.closeTheStream(
+ deleteAnyExistingFile.bind(null,
+ renameTheCurrentFile.bind(null,
+ this.openTheStream.bind(this,
+ callback))));
+ }
+
+ function deleteAnyExistingFile(cb) {
+ //on windows, you can get a EEXIST error if you rename a file to an existing file
+ //so, we'll try to delete the file we're renaming to first
+ fs.unlink(newFilename, function (err) {
+ //ignore err: if we could not delete, it's most likely that it doesn't exist
+ cb();
+ });
+ }
+
+ function renameTheCurrentFile(cb) {
+ debug("Renaming the " + filename + " -> " + newFilename);
+ fs.rename(filename, newFilename, cb);
+ }
+
+};
diff --git a/vnfmarket/src/main/webapp/vnfmarket/node_modules/log4js/lib/streams/RollingFileStream.js b/vnfmarket/src/main/webapp/vnfmarket/node_modules/log4js/lib/streams/RollingFileStream.js
new file mode 100644
index 00000000..af1e52e2
--- /dev/null
+++ b/vnfmarket/src/main/webapp/vnfmarket/node_modules/log4js/lib/streams/RollingFileStream.js
@@ -0,0 +1,117 @@
+"use strict";
+var BaseRollingFileStream = require('./BaseRollingFileStream')
+, debug = require('../debug')('RollingFileStream')
+, util = require('util')
+, path = require('path')
+, child_process = require('child_process')
+, zlib = require("zlib")
+, fs = require('fs');
+
+module.exports = RollingFileStream;
+
+function RollingFileStream (filename, size, backups, options) {
+ this.size = size;
+ this.backups = backups || 1;
+
+ function throwErrorIfArgumentsAreNotValid() {
+ if (!filename || !size || size <= 0) {
+ throw new Error("You must specify a filename and file size");
+ }
+ }
+
+ throwErrorIfArgumentsAreNotValid();
+
+ RollingFileStream.super_.call(this, filename, options);
+}
+util.inherits(RollingFileStream, BaseRollingFileStream);
+
+RollingFileStream.prototype.shouldRoll = function() {
+ debug("should roll with current size " + this.currentSize + " and max size " + this.size);
+ return this.currentSize >= this.size;
+};
+
+RollingFileStream.prototype.roll = function(filename, callback) {
+ var that = this,
+ nameMatcher = new RegExp('^' + path.basename(filename));
+
+ function justTheseFiles (item) {
+ return nameMatcher.test(item);
+ }
+
+ function index(filename_) {
+ debug('Calculating index of '+filename_);
+ return parseInt(filename_.substring((path.basename(filename) + '.').length), 10) || 0;
+ }
+
+ function byIndex(a, b) {
+ if (index(a) > index(b)) {
+ return 1;
+ } else if (index(a) < index(b) ) {
+ return -1;
+ } else {
+ return 0;
+ }
+ }
+
+ function compress (filename, cb) {
+
+ var gzip = zlib.createGzip();
+ var inp = fs.createReadStream(filename);
+ var out = fs.createWriteStream(filename+".gz");
+ inp.pipe(gzip).pipe(out);
+ fs.unlink(filename, cb);
+
+ }
+
+ function increaseFileIndex (fileToRename, cb) {
+ var idx = index(fileToRename);
+ debug('Index of ' + fileToRename + ' is ' + idx);
+ if (idx < that.backups) {
+
+ var ext = path.extname(fileToRename);
+ var destination = filename + '.' + (idx+1);
+ if (that.options.compress && /^gz$/.test(ext.substring(1))) {
+ destination+=ext;
+ }
+ //on windows, you can get a EEXIST error if you rename a file to an existing file
+ //so, we'll try to delete the file we're renaming to first
+ fs.unlink(destination, function (err) {
+ //ignore err: if we could not delete, it's most likely that it doesn't exist
+ debug('Renaming ' + fileToRename + ' -> ' + destination);
+ fs.rename(path.join(path.dirname(filename), fileToRename), destination, function(err) {
+ if (err) {
+ cb(err);
+ } else {
+ if (that.options.compress && ext!=".gz") {
+ compress(destination, cb);
+ } else {
+ cb();
+ }
+ }
+ });
+ });
+ } else {
+ cb();
+ }
+ }
+
+ function renameTheFiles(cb) {
+ //roll the backups (rename file.n to file.n+1, where n <= numBackups)
+ debug("Renaming the old files");
+ fs.readdir(path.dirname(filename), function (err, files) {
+ var filesToProcess = files.filter(justTheseFiles).sort(byIndex);
+ (function processOne(err) {
+ var file = filesToProcess.pop();
+ if (!file || err) { return cb(err); }
+ increaseFileIndex(file, processOne);
+ })();
+ });
+ }
+
+ debug("Rolling, rolling, rolling");
+ this.closeTheStream(
+ renameTheFiles.bind(null,
+ this.openTheStream.bind(this,
+ callback)));
+
+};
diff --git a/vnfmarket/src/main/webapp/vnfmarket/node_modules/log4js/lib/streams/index.js b/vnfmarket/src/main/webapp/vnfmarket/node_modules/log4js/lib/streams/index.js
new file mode 100644
index 00000000..d8e026dc
--- /dev/null
+++ b/vnfmarket/src/main/webapp/vnfmarket/node_modules/log4js/lib/streams/index.js
@@ -0,0 +1,3 @@
+"use strict";
+exports.RollingFileStream = require('./RollingFileStream');
+exports.DateRollingFileStream = require('./DateRollingFileStream');