added unit testing, and started implementing unit tests...phew

This commit is contained in:
Josh Burman
2019-03-12 22:28:02 -04:00
parent 74aad4a957
commit e8c2539f1b
3489 changed files with 464813 additions and 88 deletions

172
node_modules/winston/dist/winston.js generated vendored Normal file
View File

@ -0,0 +1,172 @@
/**
* winston.js: Top-level include defining Winston.
*
* (C) 2010 Charlie Robbins
* MIT LICENCE
*/
'use strict';
var logform = require('logform');
var _require = require('./winston/common'),
warn = _require.warn;
/**
* Setup to expose.
* @type {Object}
*/
var winston = exports;
/**
* Expose version. Use `require` method for `webpack` support.
* @type {string}
*/
winston.version = require('../package.json').version;
/**
* Include transports defined by default by winston
* @type {Array}
*/
winston.transports = require('./winston/transports');
/**
* Expose utility methods
* @type {Object}
*/
winston.config = require('./winston/config');
/**
* Hoist format-related functionality from logform.
* @type {Object}
*/
winston.addColors = logform.levels;
/**
* Hoist format-related functionality from logform.
* @type {Object}
*/
winston.format = logform.format;
/**
* Expose core Logging-related prototypes.
* @type {function}
*/
winston.createLogger = require('./winston/create-logger');
/**
* Expose core Logging-related prototypes.
* @type {Object}
*/
winston.ExceptionHandler = require('./winston/exception-handler');
/**
* Expose core Logging-related prototypes.
* @type {Object}
*/
winston.RejectionHandler = require('./winston/rejection-handler');
/**
* Expose core Logging-related prototypes.
* @type {Container}
*/
winston.Container = require('./winston/container');
/**
* Expose core Logging-related prototypes.
* @type {Object}
*/
winston.Transport = require('winston-transport');
/**
* We create and expose a default `Container` to `winston.loggers` so that the
* programmer may manage multiple `winston.Logger` instances without any
* additional overhead.
* @example
* // some-file1.js
* const logger = require('winston').loggers.get('something');
*
* // some-file2.js
* const logger = require('winston').loggers.get('something');
*/
winston.loggers = new winston.Container();
/**
* We create and expose a 'defaultLogger' so that the programmer may do the
* following without the need to create an instance of winston.Logger directly:
* @example
* const winston = require('winston');
* winston.log('info', 'some message');
* winston.error('some error');
*/
var defaultLogger = winston.createLogger(); // Pass through the target methods onto `winston.
Object.keys(winston.config.npm.levels).concat(['log', 'query', 'stream', 'add', 'remove', 'clear', 'profile', 'startTimer', 'handleExceptions', 'unhandleExceptions', 'handleRejections', 'unhandleRejections', 'configure']).forEach(function (method) {
return winston[method] = function () {
return defaultLogger[method].apply(defaultLogger, arguments);
};
});
/**
* Define getter / setter for the default logger level which need to be exposed
* by winston.
* @type {string}
*/
Object.defineProperty(winston, 'level', {
get: function get() {
return defaultLogger.level;
},
set: function set(val) {
defaultLogger.level = val;
}
});
/**
* Define getter for `exceptions` which replaces `handleExceptions` and
* `unhandleExceptions`.
* @type {Object}
*/
Object.defineProperty(winston, 'exceptions', {
get: function get() {
return defaultLogger.exceptions;
}
});
/**
* Define getters / setters for appropriate properties of the default logger
* which need to be exposed by winston.
* @type {Logger}
*/
['exitOnError'].forEach(function (prop) {
Object.defineProperty(winston, prop, {
get: function get() {
return defaultLogger[prop];
},
set: function set(val) {
defaultLogger[prop] = val;
}
});
});
/**
* The default transports and exceptionHandlers for the default winston logger.
* @type {Object}
*/
Object.defineProperty(winston, 'default', {
get: function get() {
return {
exceptionHandlers: defaultLogger.exceptionHandlers,
rejectionHandlers: defaultLogger.rejectionHandlers,
transports: defaultLogger.transports
};
}
}); // Have friendlier breakage notices for properties that were exposed by default
// on winston < 3.0.
warn.deprecated(winston, 'setLevels');
warn.forFunctions(winston, 'useFormat', ['cli']);
warn.forProperties(winston, 'useFormat', ['padLevels', 'stripColors']);
warn.forFunctions(winston, 'deprecated', ['addRewriter', 'addFilter', 'clone', 'extend']);
warn.forProperties(winston, 'deprecated', ['emitErrs', 'levelLength']); // Throw a useful error when users attempt to run `new winston.Logger`.
warn.moved(winston, 'createLogger', 'Logger');

56
node_modules/winston/dist/winston/common.js generated vendored Normal file
View File

@ -0,0 +1,56 @@
/**
* common.js: Internal helper and utility functions for winston.
*
* (C) 2010 Charlie Robbins
* MIT LICENCE
*/
'use strict';
var _require = require('util'),
format = _require.format;
/**
* Set of simple deprecation notices and a way to expose them for a set of
* properties.
* @type {Object}
* @private
*/
exports.warn = {
deprecated: function deprecated(prop) {
return function () {
throw new Error(format('{ %s } was removed in winston@3.0.0.', prop));
};
},
useFormat: function useFormat(prop) {
return function () {
throw new Error([format('{ %s } was removed in winston@3.0.0.', prop), 'Use a custom winston.format = winston.format(function) instead.'].join('\n'));
};
},
forFunctions: function forFunctions(obj, type, props) {
props.forEach(function (prop) {
obj[prop] = exports.warn[type](prop);
});
},
moved: function moved(obj, movedTo, prop) {
function movedNotice() {
return function () {
throw new Error([format('winston.%s was moved in winston@3.0.0.', prop), format('Use a winston.%s instead.', movedTo)].join('\n'));
};
}
Object.defineProperty(obj, prop, {
get: movedNotice,
set: movedNotice
});
},
forProperties: function forProperties(obj, type, props) {
props.forEach(function (prop) {
var notice = exports.warn[type](prop);
Object.defineProperty(obj, prop, {
get: notice,
set: notice
});
});
}
};

37
node_modules/winston/dist/winston/config/index.js generated vendored Normal file
View File

@ -0,0 +1,37 @@
/**
* index.js: Default settings for all levels that winston knows about.
*
* (C) 2010 Charlie Robbins
* MIT LICENCE
*/
'use strict';
var logform = require('logform');
var _require = require('triple-beam'),
configs = _require.configs;
/**
* Export config set for the CLI.
* @type {Object}
*/
exports.cli = logform.levels(configs.cli);
/**
* Export config set for npm.
* @type {Object}
*/
exports.npm = logform.levels(configs.npm);
/**
* Export config set for the syslog.
* @type {Object}
*/
exports.syslog = logform.levels(configs.syslog);
/**
* Hoist addColors from logform where it was refactored into in winston@3.
* @type {Object}
*/
exports.addColors = logform.levels;

149
node_modules/winston/dist/winston/container.js generated vendored Normal file
View File

@ -0,0 +1,149 @@
/**
* container.js: Inversion of control container for winston logger instances.
*
* (C) 2010 Charlie Robbins
* MIT LICENCE
*/
'use strict';
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
var createLogger = require('./create-logger');
/**
* Inversion of control container for winston logger instances.
* @type {Container}
*/
module.exports =
/*#__PURE__*/
function () {
/**
* Constructor function for the Container object responsible for managing a
* set of `winston.Logger` instances based on string ids.
* @param {!Object} [options={}] - Default pass-thru options for Loggers.
*/
function Container() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
_classCallCheck(this, Container);
this.loggers = new Map();
this.options = options;
}
/**
* Retreives a `winston.Logger` instance for the specified `id`. If an
* instance does not exist, one is created.
* @param {!string} id - The id of the Logger to get.
* @param {?Object} [options] - Options for the Logger instance.
* @returns {Logger} - A configured Logger instance with a specified id.
*/
_createClass(Container, [{
key: "add",
value: function add(id, options) {
var _this = this;
if (!this.loggers.has(id)) {
// Remark: Simple shallow clone for configuration options in case we pass
// in instantiated protoypal objects
options = Object.assign({}, options || this.options);
var existing = options.transports || this.options.transports; // Remark: Make sure if we have an array of transports we slice it to
// make copies of those references.
options.transports = existing ? existing.slice() : [];
var logger = createLogger(options);
logger.on('close', function () {
return _this._delete(id);
});
this.loggers.set(id, logger);
}
return this.loggers.get(id);
}
/**
* Retreives a `winston.Logger` instance for the specified `id`. If
* an instance does not exist, one is created.
* @param {!string} id - The id of the Logger to get.
* @param {?Object} [options] - Options for the Logger instance.
* @returns {Logger} - A configured Logger instance with a specified id.
*/
}, {
key: "get",
value: function get(id, options) {
return this.add(id, options);
}
/**
* Check if the container has a logger with the id.
* @param {?string} id - The id of the Logger instance to find.
* @returns {boolean} - Boolean value indicating if this instance has a
* logger with the specified `id`.
*/
}, {
key: "has",
value: function has(id) {
return !!this.loggers.has(id);
}
/**
* Closes a `Logger` instance with the specified `id` if it exists.
* If no `id` is supplied then all Loggers are closed.
* @param {?string} id - The id of the Logger instance to close.
* @returns {undefined}
*/
}, {
key: "close",
value: function close(id) {
var _this2 = this;
if (id) {
return this._removeLogger(id);
}
this.loggers.forEach(function (val, key) {
return _this2._removeLogger(key);
});
}
/**
* Remove a logger based on the id.
* @param {!string} id - The id of the logger to remove.
* @returns {undefined}
* @private
*/
}, {
key: "_removeLogger",
value: function _removeLogger(id) {
if (!this.loggers.has(id)) {
return;
}
var logger = this.loggers.get(id);
logger.close();
this._delete(id);
}
/**
* Deletes a `Logger` instance with the specified `id`.
* @param {!string} id - The id of the Logger instance to delete from
* container.
* @returns {undefined}
* @private
*/
}, {
key: "_delete",
value: function _delete(id) {
this.loggers.delete(id);
}
}]);
return Container;
}();

137
node_modules/winston/dist/winston/create-logger.js generated vendored Normal file
View File

@ -0,0 +1,137 @@
/**
* create-logger.js: Logger factory for winston logger instances.
*
* (C) 2010 Charlie Robbins
* MIT LICENCE
*/
'use strict';
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
var _require = require('triple-beam'),
LEVEL = _require.LEVEL;
var config = require('./config');
var Logger = require('./logger');
var debug = require('diagnostics')('winston:create-logger');
function isLevelEnabledFunctionName(level) {
return 'is' + level.charAt(0).toUpperCase() + level.slice(1) + 'Enabled';
}
/**
* Create a new instance of a winston Logger. Creates a new
* prototype for each instance.
* @param {!Object} opts - Options for the created logger.
* @returns {Logger} - A newly created logger instance.
*/
module.exports = function () {
var opts = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
//
// Default levels: npm
//
opts.levels = opts.levels || config.npm.levels;
/**
* DerivedLogger to attach the logs level methods.
* @type {DerivedLogger}
* @extends {Logger}
*/
var DerivedLogger =
/*#__PURE__*/
function (_Logger) {
_inherits(DerivedLogger, _Logger);
/**
* Create a new class derived logger for which the levels can be attached to
* the prototype of. This is a V8 optimization that is well know to increase
* performance of prototype functions.
* @param {!Object} options - Options for the created logger.
*/
function DerivedLogger(options) {
_classCallCheck(this, DerivedLogger);
return _possibleConstructorReturn(this, _getPrototypeOf(DerivedLogger).call(this, options));
}
return DerivedLogger;
}(Logger);
var logger = new DerivedLogger(opts); //
// Create the log level methods for the derived logger.
//
Object.keys(opts.levels).forEach(function (level) {
debug('Define prototype method for "%s"', level);
if (level === 'log') {
// eslint-disable-next-line no-console
console.warn('Level "log" not defined: conflicts with the method "log". Use a different level name.');
return;
} //
// Define prototype methods for each log level e.g.:
// logger.log('info', msg) implies these methods are defined:
// - logger.info(msg)
// - logger.isInfoEnabled()
//
// Remark: to support logger.child this **MUST** be a function
// so it'll always be called on the instance instead of a fixed
// place in the prototype chain.
//
DerivedLogger.prototype[level] = function () {
// Prefer any instance scope, but default to "root" logger
var self = this || logger; // Optimize the hot-path which is the single object.
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
if (args.length === 1) {
var msg = args[0];
var info = msg && msg.message && msg || {
message: msg
};
info.level = info[LEVEL] = level;
self._addDefaultMeta(info);
self.write(info);
return this || logger;
} // When provided nothing assume the empty string
if (args.length === 0) {
self.log(level, '');
return self;
} // Otherwise build argument list which could potentially conform to
// either:
// . v3 API: log(obj)
// 2. v1/v2 API: log(level, msg, ... [string interpolate], [{metadata}], [callback])
return self.log.apply(self, [level].concat(args));
};
DerivedLogger.prototype[isLevelEnabledFunctionName(level)] = function () {
return (this || logger).isLevelEnabled(level);
};
});
return logger;
};

290
node_modules/winston/dist/winston/exception-handler.js generated vendored Normal file
View File

@ -0,0 +1,290 @@
/**
* exception-handler.js: Object for handling uncaughtException events.
*
* (C) 2010 Charlie Robbins
* MIT LICENCE
*/
'use strict';
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
var os = require('os');
var asyncForEach = require('async/forEach');
var debug = require('diagnostics')('winston:exception');
var once = require('one-time');
var stackTrace = require('stack-trace');
var ExceptionStream = require('./exception-stream');
/**
* Object for handling uncaughtException events.
* @type {ExceptionHandler}
*/
module.exports =
/*#__PURE__*/
function () {
/**
* TODO: add contructor description
* @param {!Logger} logger - TODO: add param description
*/
function ExceptionHandler(logger) {
_classCallCheck(this, ExceptionHandler);
if (!logger) {
throw new Error('Logger is required to handle exceptions');
}
this.logger = logger;
this.handlers = new Map();
}
/**
* Handles `uncaughtException` events for the current process by adding any
* handlers passed in.
* @returns {undefined}
*/
_createClass(ExceptionHandler, [{
key: "handle",
value: function handle() {
var _this = this;
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
args.forEach(function (arg) {
if (Array.isArray(arg)) {
return arg.forEach(function (handler) {
return _this._addHandler(handler);
});
}
_this._addHandler(arg);
});
if (!this.catcher) {
this.catcher = this._uncaughtException.bind(this);
process.on('uncaughtException', this.catcher);
}
}
/**
* Removes any handlers to `uncaughtException` events for the current
* process. This does not modify the state of the `this.handlers` set.
* @returns {undefined}
*/
}, {
key: "unhandle",
value: function unhandle() {
var _this2 = this;
if (this.catcher) {
process.removeListener('uncaughtException', this.catcher);
this.catcher = false;
Array.from(this.handlers.values()).forEach(function (wrapper) {
return _this2.logger.unpipe(wrapper);
});
}
}
/**
* TODO: add method description
* @param {Error} err - Error to get information about.
* @returns {mixed} - TODO: add return description.
*/
}, {
key: "getAllInfo",
value: function getAllInfo(err) {
var message = err.message;
if (!message && typeof err === 'string') {
message = err;
}
return {
error: err,
// TODO (indexzero): how do we configure this?
level: 'error',
message: ["uncaughtException: ".concat(message || '(no error message)'), err.stack || ' No stack trace'].join('\n'),
stack: err.stack,
exception: true,
date: new Date().toString(),
process: this.getProcessInfo(),
os: this.getOsInfo(),
trace: this.getTrace(err)
};
}
/**
* Gets all relevant process information for the currently running process.
* @returns {mixed} - TODO: add return description.
*/
}, {
key: "getProcessInfo",
value: function getProcessInfo() {
return {
pid: process.pid,
uid: process.getuid ? process.getuid() : null,
gid: process.getgid ? process.getgid() : null,
cwd: process.cwd(),
execPath: process.execPath,
version: process.version,
argv: process.argv,
memoryUsage: process.memoryUsage()
};
}
/**
* Gets all relevant OS information for the currently running process.
* @returns {mixed} - TODO: add return description.
*/
}, {
key: "getOsInfo",
value: function getOsInfo() {
return {
loadavg: os.loadavg(),
uptime: os.uptime()
};
}
/**
* Gets a stack trace for the specified error.
* @param {mixed} err - TODO: add param description.
* @returns {mixed} - TODO: add return description.
*/
}, {
key: "getTrace",
value: function getTrace(err) {
var trace = err ? stackTrace.parse(err) : stackTrace.get();
return trace.map(function (site) {
return {
column: site.getColumnNumber(),
file: site.getFileName(),
function: site.getFunctionName(),
line: site.getLineNumber(),
method: site.getMethodName(),
native: site.isNative()
};
});
}
/**
* Helper method to add a transport as an exception handler.
* @param {Transport} handler - The transport to add as an exception handler.
* @returns {void}
*/
}, {
key: "_addHandler",
value: function _addHandler(handler) {
if (!this.handlers.has(handler)) {
handler.handleExceptions = true;
var wrapper = new ExceptionStream(handler);
this.handlers.set(handler, wrapper);
this.logger.pipe(wrapper);
}
}
/**
* Logs all relevant information around the `err` and exits the current
* process.
* @param {Error} err - Error to handle
* @returns {mixed} - TODO: add return description.
* @private
*/
}, {
key: "_uncaughtException",
value: function _uncaughtException(err) {
var info = this.getAllInfo(err);
var handlers = this._getExceptionHandlers(); // Calculate if we should exit on this error
var doExit = typeof this.logger.exitOnError === 'function' ? this.logger.exitOnError(err) : this.logger.exitOnError;
var timeout;
if (!handlers.length && doExit) {
// eslint-disable-next-line no-console
console.warn('winston: exitOnError cannot be true with no exception handlers.'); // eslint-disable-next-line no-console
console.warn('winston: not exiting process.');
doExit = false;
}
function gracefulExit() {
debug('doExit', doExit);
debug('process._exiting', process._exiting);
if (doExit && !process._exiting) {
// Remark: Currently ignoring any exceptions from transports when
// catching uncaught exceptions.
if (timeout) {
clearTimeout(timeout);
} // eslint-disable-next-line no-process-exit
process.exit(1);
}
}
if (!handlers || handlers.length === 0) {
return process.nextTick(gracefulExit);
} // Log to all transports attempting to listen for when they are completed.
asyncForEach(handlers, function (handler, next) {
var done = once(next);
var transport = handler.transport || handler; // Debug wrapping so that we can inspect what's going on under the covers.
function onDone(event) {
return function () {
debug(event);
done();
};
}
transport._ending = true;
transport.once('finish', onDone('finished'));
transport.once('error', onDone('error'));
}, function () {
return doExit && gracefulExit();
});
this.logger.log(info); // If exitOnError is true, then only allow the logging of exceptions to
// take up to `3000ms`.
if (doExit) {
timeout = setTimeout(gracefulExit, 3000);
}
}
/**
* Returns the list of transports and exceptionHandlers for this instance.
* @returns {Array} - List of transports and exceptionHandlers for this
* instance.
* @private
*/
}, {
key: "_getExceptionHandlers",
value: function _getExceptionHandlers() {
// Remark (indexzero): since `logger.transports` returns all of the pipes
// from the _readableState of the stream we actually get the join of the
// explicit handlers and the implicit transports with
// `handleExceptions: true`
return this.logger.transports.filter(function (wrap) {
var transport = wrap.transport || wrap;
return transport.handleExceptions;
});
}
}]);
return ExceptionHandler;
}();

90
node_modules/winston/dist/winston/exception-stream.js generated vendored Normal file
View File

@ -0,0 +1,90 @@
/**
* exception-stream.js: TODO: add file header handler.
*
* (C) 2010 Charlie Robbins
* MIT LICENCE
*/
'use strict';
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
var _require = require('readable-stream'),
Writable = _require.Writable;
/**
* TODO: add class description.
* @type {ExceptionStream}
* @extends {Writable}
*/
module.exports =
/*#__PURE__*/
function (_Writable) {
_inherits(ExceptionStream, _Writable);
/**
* Constructor function for the ExceptionStream responsible for wrapping a
* TransportStream; only allowing writes of `info` objects with
* `info.exception` set to true.
* @param {!TransportStream} transport - Stream to filter to exceptions
*/
function ExceptionStream(transport) {
var _this;
_classCallCheck(this, ExceptionStream);
_this = _possibleConstructorReturn(this, _getPrototypeOf(ExceptionStream).call(this, {
objectMode: true
}));
if (!transport) {
throw new Error('ExceptionStream requires a TransportStream instance.');
} // Remark (indexzero): we set `handleExceptions` here because it's the
// predicate checked in ExceptionHandler.prototype.__getExceptionHandlers
_this.handleExceptions = true;
_this.transport = transport;
return _this;
}
/**
* Writes the info object to our transport instance if (and only if) the
* `exception` property is set on the info.
* @param {mixed} info - TODO: add param description.
* @param {mixed} enc - TODO: add param description.
* @param {mixed} callback - TODO: add param description.
* @returns {mixed} - TODO: add return description.
* @private
*/
_createClass(ExceptionStream, [{
key: "_write",
value: function _write(info, enc, callback) {
if (info.exception) {
return this.transport.log(info, callback);
}
callback();
return true;
}
}]);
return ExceptionStream;
}(Writable);

742
node_modules/winston/dist/winston/logger.js generated vendored Normal file
View File

@ -0,0 +1,742 @@
/**
* logger.js: TODO: add file header description.
*
* (C) 2010 Charlie Robbins
* MIT LICENCE
*/
'use strict';
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
var _require = require('readable-stream'),
Stream = _require.Stream,
Transform = _require.Transform;
var asyncForEach = require('async/forEach');
var _require2 = require('triple-beam'),
LEVEL = _require2.LEVEL,
SPLAT = _require2.SPLAT;
var isStream = require('is-stream');
var ExceptionHandler = require('./exception-handler');
var RejectionHandler = require('./rejection-handler');
var LegacyTransportStream = require('winston-transport/legacy');
var Profiler = require('./profiler');
var _require3 = require('./common'),
warn = _require3.warn;
var config = require('./config');
/**
* Captures the number of format (i.e. %s strings) in a given string.
* Based on `util.format`, see Node.js source:
* https://github.com/nodejs/node/blob/b1c8f15c5f169e021f7c46eb7b219de95fe97603/lib/util.js#L201-L230
* @type {RegExp}
*/
var formatRegExp = /%[scdjifoO%]/g;
/**
* TODO: add class description.
* @type {Logger}
* @extends {Transform}
*/
var Logger =
/*#__PURE__*/
function (_Transform) {
_inherits(Logger, _Transform);
/**
* Constructor function for the Logger object responsible for persisting log
* messages and metadata to one or more transports.
* @param {!Object} options - foo
*/
function Logger(options) {
var _this;
_classCallCheck(this, Logger);
_this = _possibleConstructorReturn(this, _getPrototypeOf(Logger).call(this, {
objectMode: true
}));
_this.configure(options);
return _this;
}
_createClass(Logger, [{
key: "child",
value: function child(defaultRequestMetadata) {
var logger = this;
return Object.create(logger, {
write: {
value: function value(info) {
var infoClone = Object.assign({}, defaultRequestMetadata, info); // Object.assign doesn't copy inherited Error
// properties so we have to do that explicitly
//
// Remark (indexzero): we should remove this
// since the errors format will handle this case.
//
if (info instanceof Error) {
infoClone.stack = info.stack;
infoClone.message = info.message;
}
logger.write(infoClone);
}
}
});
}
/**
* This will wholesale reconfigure this instance by:
* 1. Resetting all transports. Older transports will be removed implicitly.
* 2. Set all other options including levels, colors, rewriters, filters,
* exceptionHandlers, etc.
* @param {!Object} options - TODO: add param description.
* @returns {undefined}
*/
}, {
key: "configure",
value: function configure() {
var _this2 = this;
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
silent = _ref.silent,
format = _ref.format,
defaultMeta = _ref.defaultMeta,
levels = _ref.levels,
_ref$level = _ref.level,
level = _ref$level === void 0 ? 'info' : _ref$level,
_ref$exitOnError = _ref.exitOnError,
exitOnError = _ref$exitOnError === void 0 ? true : _ref$exitOnError,
transports = _ref.transports,
colors = _ref.colors,
emitErrs = _ref.emitErrs,
formatters = _ref.formatters,
padLevels = _ref.padLevels,
rewriters = _ref.rewriters,
stripColors = _ref.stripColors,
exceptionHandlers = _ref.exceptionHandlers,
rejectionHandlers = _ref.rejectionHandlers;
// Reset transports if we already have them
if (this.transports.length) {
this.clear();
}
this.silent = silent;
this.format = format || this.format || require('logform/json')();
this.defaultMeta = defaultMeta || null; // Hoist other options onto this instance.
this.levels = levels || this.levels || config.npm.levels;
this.level = level;
this.exceptions = new ExceptionHandler(this);
this.rejections = new RejectionHandler(this);
this.profilers = {};
this.exitOnError = exitOnError; // Add all transports we have been provided.
if (transports) {
transports = Array.isArray(transports) ? transports : [transports];
transports.forEach(function (transport) {
return _this2.add(transport);
});
}
if (colors || emitErrs || formatters || padLevels || rewriters || stripColors) {
throw new Error(['{ colors, emitErrs, formatters, padLevels, rewriters, stripColors } were removed in winston@3.0.0.', 'Use a custom winston.format(function) instead.', 'See: https://github.com/winstonjs/winston/tree/master/UPGRADE-3.0.md'].join('\n'));
}
if (exceptionHandlers) {
this.exceptions.handle(exceptionHandlers);
}
if (rejectionHandlers) {
this.rejections.handle(rejectionHandlers);
}
}
}, {
key: "isLevelEnabled",
value: function isLevelEnabled(level) {
var _this3 = this;
var givenLevelValue = getLevelValue(this.levels, level);
if (givenLevelValue === null) {
return false;
}
var configuredLevelValue = getLevelValue(this.levels, this.level);
if (configuredLevelValue === null) {
return false;
}
if (!this.transports || this.transports.length === 0) {
return configuredLevelValue >= givenLevelValue;
}
var index = this.transports.findIndex(function (transport) {
var transportLevelValue = getLevelValue(_this3.levels, transport.level);
if (transportLevelValue === null) {
transportLevelValue = configuredLevelValue;
}
return transportLevelValue >= givenLevelValue;
});
return index !== -1;
}
/* eslint-disable valid-jsdoc */
/**
* Ensure backwards compatibility with a `log` method
* @param {mixed} level - Level the log message is written at.
* @param {mixed} msg - TODO: add param description.
* @param {mixed} meta - TODO: add param description.
* @returns {Logger} - TODO: add return description.
*
* @example
* // Supports the existing API:
* logger.log('info', 'Hello world', { custom: true });
* logger.log('info', new Error('Yo, it\'s on fire'));
*
* // Requires winston.format.splat()
* logger.log('info', '%s %d%%', 'A string', 50, { thisIsMeta: true });
*
* // And the new API with a single JSON literal:
* logger.log({ level: 'info', message: 'Hello world', custom: true });
* logger.log({ level: 'info', message: new Error('Yo, it\'s on fire') });
*
* // Also requires winston.format.splat()
* logger.log({
* level: 'info',
* message: '%s %d%%',
* [SPLAT]: ['A string', 50],
* meta: { thisIsMeta: true }
* });
*
*/
/* eslint-enable valid-jsdoc */
}, {
key: "log",
value: function log(level, msg) {
var _Object$assign2;
for (var _len = arguments.length, splat = new Array(_len > 2 ? _len - 2 : 0), _key = 2; _key < _len; _key++) {
splat[_key - 2] = arguments[_key];
}
// eslint-disable-line max-params
// Optimize for the hotpath of logging JSON literals
if (arguments.length === 1) {
// Yo dawg, I heard you like levels ... seriously ...
// In this context the LHS `level` here is actually the `info` so read
// this as: info[LEVEL] = info.level;
level[LEVEL] = level.level;
this._addDefaultMeta(level);
this.write(level);
return this;
} // Slightly less hotpath, but worth optimizing for.
if (arguments.length === 2) {
var _this$write;
if (msg && _typeof(msg) === 'object') {
msg[LEVEL] = msg.level = level;
this._addDefaultMeta(msg);
this.write(msg);
return this;
}
this.write((_this$write = {}, _defineProperty(_this$write, LEVEL, level), _defineProperty(_this$write, "level", level), _defineProperty(_this$write, "message", msg), _this$write));
return this;
}
var meta = splat[0];
if (_typeof(meta) === 'object' && meta !== null) {
// Extract tokens, if none available default to empty array to
// ensure consistancy in expected results
var tokens = msg && msg.match && msg.match(formatRegExp);
if (!tokens) {
var _Object$assign;
var info = Object.assign({}, this.defaultMeta, meta, (_Object$assign = {}, _defineProperty(_Object$assign, LEVEL, level), _defineProperty(_Object$assign, SPLAT, splat), _defineProperty(_Object$assign, "level", level), _defineProperty(_Object$assign, "message", msg), _Object$assign));
if (meta.message) info.message += "".concat(meta.message);
if (meta.stack) info.stack = meta.stack;
this.write(info);
return this;
}
}
this.write(Object.assign({}, this.defaultMeta, (_Object$assign2 = {}, _defineProperty(_Object$assign2, LEVEL, level), _defineProperty(_Object$assign2, SPLAT, splat), _defineProperty(_Object$assign2, "level", level), _defineProperty(_Object$assign2, "message", msg), _Object$assign2)));
return this;
}
/**
* Pushes data so that it can be picked up by all of our pipe targets.
* @param {mixed} info - TODO: add param description.
* @param {mixed} enc - TODO: add param description.
* @param {mixed} callback - Continues stream processing.
* @returns {undefined}
* @private
*/
}, {
key: "_transform",
value: function _transform(info, enc, callback) {
if (this.silent) {
return callback();
} // [LEVEL] is only soft guaranteed to be set here since we are a proper
// stream. It is likely that `info` came in through `.log(info)` or
// `.info(info)`. If it is not defined, however, define it.
// This LEVEL symbol is provided by `triple-beam` and also used in:
// - logform
// - winston-transport
// - abstract-winston-transport
if (!info[LEVEL]) {
info[LEVEL] = info.level;
} // Remark: really not sure what to do here, but this has been reported as
// very confusing by pre winston@2.0.0 users as quite confusing when using
// custom levels.
if (!this.levels[info[LEVEL]] && this.levels[info[LEVEL]] !== 0) {
// eslint-disable-next-line no-console
console.error('[winston] Unknown logger level: %s', info[LEVEL]);
} // Remark: not sure if we should simply error here.
if (!this._readableState.pipes) {
// eslint-disable-next-line no-console
console.error('[winston] Attempt to write logs with no transports %j', info);
} // Here we write to the `format` pipe-chain, which on `readable` above will
// push the formatted `info` Object onto the buffer for this instance. We trap
// (and re-throw) any errors generated by the user-provided format, but also
// guarantee that the streams callback is invoked so that we can continue flowing.
try {
this.push(this.format.transform(info, this.format.options));
} catch (ex) {
throw ex;
} finally {
// eslint-disable-next-line callback-return
callback();
}
}
/**
* Delays the 'finish' event until all transport pipe targets have
* also emitted 'finish' or are already finished.
* @param {mixed} callback - Continues stream processing.
*/
}, {
key: "_final",
value: function _final(callback) {
var transports = this.transports.slice();
asyncForEach(transports, function (transport, next) {
if (!transport || transport.finished) return setImmediate(next);
transport.once('finish', next);
transport.end();
}, callback);
}
/**
* Adds the transport to this logger instance by piping to it.
* @param {mixed} transport - TODO: add param description.
* @returns {Logger} - TODO: add return description.
*/
}, {
key: "add",
value: function add(transport) {
// Support backwards compatibility with all existing `winston < 3.x.x`
// transports which meet one of two criteria:
// 1. They inherit from winston.Transport in < 3.x.x which is NOT a stream.
// 2. They expose a log method which has a length greater than 2 (i.e. more then
// just `log(info, callback)`.
var target = !isStream(transport) || transport.log.length > 2 ? new LegacyTransportStream({
transport: transport
}) : transport;
if (!target._writableState || !target._writableState.objectMode) {
throw new Error('Transports must WritableStreams in objectMode. Set { objectMode: true }.');
} // Listen for the `error` event and the `warn` event on the new Transport.
this._onEvent('error', target);
this._onEvent('warn', target);
this.pipe(target);
if (transport.handleExceptions) {
this.exceptions.handle();
}
if (transport.handleRejections) {
this.rejections.handle();
}
return this;
}
/**
* Removes the transport from this logger instance by unpiping from it.
* @param {mixed} transport - TODO: add param description.
* @returns {Logger} - TODO: add return description.
*/
}, {
key: "remove",
value: function remove(transport) {
var target = transport;
if (!isStream(transport) || transport.log.length > 2) {
target = this.transports.filter(function (match) {
return match.transport === transport;
})[0];
}
if (target) {
this.unpipe(target);
}
return this;
}
/**
* Removes all transports from this logger instance.
* @returns {Logger} - TODO: add return description.
*/
}, {
key: "clear",
value: function clear() {
this.unpipe();
return this;
}
/**
* Cleans up resources (streams, event listeners) for all transports
* associated with this instance (if necessary).
* @returns {Logger} - TODO: add return description.
*/
}, {
key: "close",
value: function close() {
this.clear();
this.emit('close');
return this;
}
/**
* Sets the `target` levels specified on this instance.
* @param {Object} Target levels to use on this instance.
*/
}, {
key: "setLevels",
value: function setLevels() {
warn.deprecated('setLevels');
}
/**
* Queries the all transports for this instance with the specified `options`.
* This will aggregate each transport's results into one object containing
* a property per transport.
* @param {Object} options - Query options for this instance.
* @param {function} callback - Continuation to respond to when complete.
*/
}, {
key: "query",
value: function query(options, callback) {
if (typeof options === 'function') {
callback = options;
options = {};
}
options = options || {};
var results = {};
var queryObject = Object.assign({}, options.query || {}); // Helper function to query a single transport
function queryTransport(transport, next) {
if (options.query && typeof transport.formatQuery === 'function') {
options.query = transport.formatQuery(queryObject);
}
transport.query(options, function (err, res) {
if (err) {
return next(err);
}
if (typeof transport.formatResults === 'function') {
res = transport.formatResults(res, options.format);
}
next(null, res);
});
} // Helper function to accumulate the results from `queryTransport` into
// the `results`.
function addResults(transport, next) {
queryTransport(transport, function (err, result) {
// queryTransport could potentially invoke the callback multiple times
// since Transport code can be unpredictable.
if (next) {
result = err || result;
if (result) {
results[transport.name] = result;
} // eslint-disable-next-line callback-return
next();
}
next = null;
});
} // Iterate over the transports in parallel setting the appropriate key in
// the `results`.
asyncForEach(this.transports.filter(function (transport) {
return !!transport.query;
}), addResults, function () {
return callback(null, results);
});
}
/**
* Returns a log stream for all transports. Options object is optional.
* @param{Object} options={} - Stream options for this instance.
* @returns {Stream} - TODO: add return description.
*/
}, {
key: "stream",
value: function stream() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var out = new Stream();
var streams = [];
out._streams = streams;
out.destroy = function () {
var i = streams.length;
while (i--) {
streams[i].destroy();
}
}; // Create a list of all transports for this instance.
this.transports.filter(function (transport) {
return !!transport.stream;
}).forEach(function (transport) {
var str = transport.stream(options);
if (!str) {
return;
}
streams.push(str);
str.on('log', function (log) {
log.transport = log.transport || [];
log.transport.push(transport.name);
out.emit('log', log);
});
str.on('error', function (err) {
err.transport = err.transport || [];
err.transport.push(transport.name);
out.emit('error', err);
});
});
return out;
}
/**
* Returns an object corresponding to a specific timing. When done is called
* the timer will finish and log the duration. e.g.:
* @returns {Profile} - TODO: add return description.
* @example
* const timer = winston.startTimer()
* setTimeout(() => {
* timer.done({
* message: 'Logging message'
* });
* }, 1000);
*/
}, {
key: "startTimer",
value: function startTimer() {
return new Profiler(this);
}
/**
* Tracks the time inbetween subsequent calls to this method with the same
* `id` parameter. The second call to this method will log the difference in
* milliseconds along with the message.
* @param {string} id Unique id of the profiler
* @returns {Logger} - TODO: add return description.
*/
}, {
key: "profile",
value: function profile(id) {
var time = Date.now();
if (this.profilers[id]) {
var timeEnd = this.profilers[id];
delete this.profilers[id]; // Attempt to be kind to users if they are still using older APIs.
for (var _len2 = arguments.length, args = new Array(_len2 > 1 ? _len2 - 1 : 0), _key2 = 1; _key2 < _len2; _key2++) {
args[_key2 - 1] = arguments[_key2];
}
if (typeof args[args.length - 2] === 'function') {
// eslint-disable-next-line no-console
console.warn('Callback function no longer supported as of winston@3.0.0');
args.pop();
} // Set the duration property of the metadata
var info = _typeof(args[args.length - 1]) === 'object' ? args.pop() : {};
info.level = info.level || 'info';
info.durationMs = time - timeEnd;
info.message = info.message || id;
return this.write(info);
}
this.profilers[id] = time;
return this;
}
/**
* Backwards compatibility to `exceptions.handle` in winston < 3.0.0.
* @returns {undefined}
* @deprecated
*/
}, {
key: "handleExceptions",
value: function handleExceptions() {
var _this$exceptions;
// eslint-disable-next-line no-console
console.warn('Deprecated: .handleExceptions() will be removed in winston@4. Use .exceptions.handle()');
(_this$exceptions = this.exceptions).handle.apply(_this$exceptions, arguments);
}
/**
* Backwards compatibility to `exceptions.handle` in winston < 3.0.0.
* @returns {undefined}
* @deprecated
*/
}, {
key: "unhandleExceptions",
value: function unhandleExceptions() {
var _this$exceptions2;
// eslint-disable-next-line no-console
console.warn('Deprecated: .unhandleExceptions() will be removed in winston@4. Use .exceptions.unhandle()');
(_this$exceptions2 = this.exceptions).unhandle.apply(_this$exceptions2, arguments);
}
/**
* Throw a more meaningful deprecation notice
* @throws {Error} - TODO: add throws description.
*/
}, {
key: "cli",
value: function cli() {
throw new Error(['Logger.cli() was removed in winston@3.0.0', 'Use a custom winston.formats.cli() instead.', 'See: https://github.com/winstonjs/winston/tree/master/UPGRADE-3.0.md'].join('\n'));
}
/**
* Bubbles the `event` that occured on the specified `transport` up
* from this instance.
* @param {string} event - The event that occured
* @param {Object} transport - Transport on which the event occured
* @private
*/
}, {
key: "_onEvent",
value: function _onEvent(event, transport) {
function transportEvent(err) {
this.emit(event, err, transport);
}
if (!transport['__winston' + event]) {
transport['__winston' + event] = transportEvent.bind(this);
transport.on(event, transport['__winston' + event]);
}
}
}, {
key: "_addDefaultMeta",
value: function _addDefaultMeta(msg) {
if (this.defaultMeta) {
Object.assign(msg, this.defaultMeta);
}
}
}]);
return Logger;
}(Transform);
function getLevelValue(levels, level) {
var value = levels[level];
if (!value && value !== 0) {
return null;
}
return value;
}
/**
* Represents the current readableState pipe targets for this Logger instance.
* @type {Array|Object}
*/
Object.defineProperty(Logger.prototype, 'transports', {
configurable: false,
enumerable: true,
get: function get() {
var pipes = this._readableState.pipes;
return !Array.isArray(pipes) ? [pipes].filter(Boolean) : pipes;
}
});
module.exports = Logger;

71
node_modules/winston/dist/winston/profiler.js generated vendored Normal file
View File

@ -0,0 +1,71 @@
/**
* profiler.js: TODO: add file header description.
*
* (C) 2010 Charlie Robbins
* MIT LICENCE
*/
'use strict';
/**
* TODO: add class description.
* @type {Profiler}
* @private
*/
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
module.exports =
/*#__PURE__*/
function () {
/**
* Constructor function for the Profiler instance used by
* `Logger.prototype.startTimer`. When done is called the timer will finish
* and log the duration.
* @param {!Logger} logger - TODO: add param description.
* @private
*/
function Profiler(logger) {
_classCallCheck(this, Profiler);
if (!logger) {
throw new Error('Logger is required for profiling.');
}
this.logger = logger;
this.start = Date.now();
}
/**
* Ends the current timer (i.e. Profiler) instance and logs the `msg` along
* with the duration since creation.
* @returns {mixed} - TODO: add return description.
* @private
*/
_createClass(Profiler, [{
key: "done",
value: function done() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
if (typeof args[args.length - 1] === 'function') {
// eslint-disable-next-line no-console
console.warn('Callback function no longer supported as of winston@3.0.0');
args.pop();
}
var info = _typeof(args[args.length - 1]) === 'object' ? args.pop() : {};
info.level = info.level || 'info';
info.durationMs = Date.now() - this.start;
return this.logger.write(info);
}
}]);
return Profiler;
}();

290
node_modules/winston/dist/winston/rejection-handler.js generated vendored Normal file
View File

@ -0,0 +1,290 @@
/**
* exception-handler.js: Object for handling uncaughtException events.
*
* (C) 2010 Charlie Robbins
* MIT LICENCE
*/
'use strict';
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
var os = require('os');
var asyncForEach = require('async/forEach');
var debug = require('diagnostics')('winston:rejection');
var once = require('one-time');
var stackTrace = require('stack-trace');
var ExceptionStream = require('./exception-stream');
/**
* Object for handling unhandledRejection events.
* @type {RejectionHandler}
*/
module.exports =
/*#__PURE__*/
function () {
/**
* TODO: add contructor description
* @param {!Logger} logger - TODO: add param description
*/
function RejectionHandler(logger) {
_classCallCheck(this, RejectionHandler);
if (!logger) {
throw new Error('Logger is required to handle rejections');
}
this.logger = logger;
this.handlers = new Map();
}
/**
* Handles `unhandledRejection` events for the current process by adding any
* handlers passed in.
* @returns {undefined}
*/
_createClass(RejectionHandler, [{
key: "handle",
value: function handle() {
var _this = this;
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {
args[_key] = arguments[_key];
}
args.forEach(function (arg) {
if (Array.isArray(arg)) {
return arg.forEach(function (handler) {
return _this._addHandler(handler);
});
}
_this._addHandler(arg);
});
if (!this.catcher) {
this.catcher = this._unhandledRejection.bind(this);
process.on('unhandledRejection', this.catcher);
}
}
/**
* Removes any handlers to `unhandledRejection` events for the current
* process. This does not modify the state of the `this.handlers` set.
* @returns {undefined}
*/
}, {
key: "unhandle",
value: function unhandle() {
var _this2 = this;
if (this.catcher) {
process.removeListener('unhandledRejection', this.catcher);
this.catcher = false;
Array.from(this.handlers.values()).forEach(function (wrapper) {
return _this2.logger.unpipe(wrapper);
});
}
}
/**
* TODO: add method description
* @param {Error} err - Error to get information about.
* @returns {mixed} - TODO: add return description.
*/
}, {
key: "getAllInfo",
value: function getAllInfo(err) {
var message = err.message;
if (!message && typeof err === 'string') {
message = err;
}
return {
error: err,
// TODO (indexzero): how do we configure this?
level: 'error',
message: ["unhandledRejection: ".concat(message || '(no error message)'), err.stack || ' No stack trace'].join('\n'),
stack: err.stack,
exception: true,
date: new Date().toString(),
process: this.getProcessInfo(),
os: this.getOsInfo(),
trace: this.getTrace(err)
};
}
/**
* Gets all relevant process information for the currently running process.
* @returns {mixed} - TODO: add return description.
*/
}, {
key: "getProcessInfo",
value: function getProcessInfo() {
return {
pid: process.pid,
uid: process.getuid ? process.getuid() : null,
gid: process.getgid ? process.getgid() : null,
cwd: process.cwd(),
execPath: process.execPath,
version: process.version,
argv: process.argv,
memoryUsage: process.memoryUsage()
};
}
/**
* Gets all relevant OS information for the currently running process.
* @returns {mixed} - TODO: add return description.
*/
}, {
key: "getOsInfo",
value: function getOsInfo() {
return {
loadavg: os.loadavg(),
uptime: os.uptime()
};
}
/**
* Gets a stack trace for the specified error.
* @param {mixed} err - TODO: add param description.
* @returns {mixed} - TODO: add return description.
*/
}, {
key: "getTrace",
value: function getTrace(err) {
var trace = err ? stackTrace.parse(err) : stackTrace.get();
return trace.map(function (site) {
return {
column: site.getColumnNumber(),
file: site.getFileName(),
function: site.getFunctionName(),
line: site.getLineNumber(),
method: site.getMethodName(),
native: site.isNative()
};
});
}
/**
* Helper method to add a transport as an exception handler.
* @param {Transport} handler - The transport to add as an exception handler.
* @returns {void}
*/
}, {
key: "_addHandler",
value: function _addHandler(handler) {
if (!this.handlers.has(handler)) {
handler.handleExceptions = true;
var wrapper = new ExceptionStream(handler);
this.handlers.set(handler, wrapper);
this.logger.pipe(wrapper);
}
}
/**
* Logs all relevant information around the `err` and exits the current
* process.
* @param {Error} err - Error to handle
* @returns {mixed} - TODO: add return description.
* @private
*/
}, {
key: "_unhandledRejection",
value: function _unhandledRejection(err) {
var info = this.getAllInfo(err);
var handlers = this._getRejectionHandlers(); // Calculate if we should exit on this error
var doExit = typeof this.logger.exitOnError === 'function' ? this.logger.exitOnError(err) : this.logger.exitOnError;
var timeout;
if (!handlers.length && doExit) {
// eslint-disable-next-line no-console
console.warn('winston: exitOnError cannot be true with no rejection handlers.'); // eslint-disable-next-line no-console
console.warn('winston: not exiting process.');
doExit = false;
}
function gracefulExit() {
debug('doExit', doExit);
debug('process._exiting', process._exiting);
if (doExit && !process._exiting) {
// Remark: Currently ignoring any rejections from transports when
// catching unhandled rejections.
if (timeout) {
clearTimeout(timeout);
} // eslint-disable-next-line no-process-exit
process.exit(1);
}
}
if (!handlers || handlers.length === 0) {
return process.nextTick(gracefulExit);
} // Log to all transports attempting to listen for when they are completed.
asyncForEach(handlers, function (handler, next) {
var done = once(next);
var transport = handler.transport || handler; // Debug wrapping so that we can inspect what's going on under the covers.
function onDone(event) {
return function () {
debug(event);
done();
};
}
transport._ending = true;
transport.once('finish', onDone('finished'));
transport.once('error', onDone('error'));
}, function () {
return doExit && gracefulExit();
});
this.logger.log(info); // If exitOnError is true, then only allow the logging of exceptions to
// take up to `3000ms`.
if (doExit) {
timeout = setTimeout(gracefulExit, 3000);
}
}
/**
* Returns the list of transports and exceptionHandlers for this instance.
* @returns {Array} - List of transports and exceptionHandlers for this
* instance.
* @private
*/
}, {
key: "_getRejectionHandlers",
value: function _getRejectionHandlers() {
// Remark (indexzero): since `logger.transports` returns all of the pipes
// from the _readableState of the stream we actually get the join of the
// explicit handlers and the implicit transports with
// `handleRejections: true`
return this.logger.transports.filter(function (wrap) {
var transport = wrap.transport || wrap;
return transport.handleRejections;
});
}
}]);
return RejectionHandler;
}();

135
node_modules/winston/dist/winston/tail-file.js generated vendored Normal file
View File

@ -0,0 +1,135 @@
/**
* tail-file.js: TODO: add file header description.
*
* (C) 2010 Charlie Robbins
* MIT LICENCE
*/
'use strict';
var fs = require('fs');
var _require = require('string_decoder'),
StringDecoder = _require.StringDecoder;
var _require2 = require('readable-stream'),
Stream = _require2.Stream;
/**
* Simple no-op function.
* @returns {undefined}
*/
function noop() {}
/**
* TODO: add function description.
* @param {Object} options - Options for tail.
* @param {function} iter - Iterator function to execute on every line.
* `tail -f` a file. Options must include file.
* @returns {mixed} - TODO: add return description.
*/
module.exports = function (options, iter) {
var buffer = Buffer.alloc(64 * 1024);
var decode = new StringDecoder('utf8');
var stream = new Stream();
var buff = '';
var pos = 0;
var row = 0;
if (options.start === -1) {
delete options.start;
}
stream.readable = true;
stream.destroy = function () {
stream.destroyed = true;
stream.emit('end');
stream.emit('close');
};
fs.open(options.file, 'a+', '0644', function (err, fd) {
if (err) {
if (!iter) {
stream.emit('error', err);
} else {
iter(err);
}
stream.destroy();
return;
}
(function read() {
if (stream.destroyed) {
fs.close(fd, noop);
return;
}
return fs.read(fd, buffer, 0, buffer.length, pos, function (err, bytes) {
if (err) {
if (!iter) {
stream.emit('error', err);
} else {
iter(err);
}
stream.destroy();
return;
}
if (!bytes) {
if (buff) {
// eslint-disable-next-line eqeqeq
if (options.start == null || row > options.start) {
if (!iter) {
stream.emit('line', buff);
} else {
iter(null, buff);
}
}
row++;
buff = '';
}
return setTimeout(read, 1000);
}
var data = decode.write(buffer.slice(0, bytes));
if (!iter) {
stream.emit('data', data);
}
data = (buff + data).split(/\n+/);
var l = data.length - 1;
var i = 0;
for (; i < l; i++) {
// eslint-disable-next-line eqeqeq
if (options.start == null || row > options.start) {
if (!iter) {
stream.emit('line', data[i]);
} else {
iter(null, data[i]);
}
}
row++;
}
buff = data[l];
pos += bytes;
return read();
});
})();
});
if (!iter) {
return stream;
}
return stream.destroy;
};

162
node_modules/winston/dist/winston/transports/console.js generated vendored Normal file
View File

@ -0,0 +1,162 @@
/* eslint-disable no-console */
/*
* console.js: Transport for outputting to the console.
*
* (C) 2010 Charlie Robbins
* MIT LICENCE
*/
'use strict';
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
var os = require('os');
var _require = require('triple-beam'),
LEVEL = _require.LEVEL,
MESSAGE = _require.MESSAGE;
var TransportStream = require('winston-transport');
/**
* Transport for outputting to the console.
* @type {Console}
* @extends {TransportStream}
*/
module.exports =
/*#__PURE__*/
function (_TransportStream) {
_inherits(Console, _TransportStream);
/**
* Constructor function for the Console transport object responsible for
* persisting log messages and metadata to a terminal or TTY.
* @param {!Object} [options={}] - Options for this instance.
*/
function Console() {
var _this;
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
_classCallCheck(this, Console);
_this = _possibleConstructorReturn(this, _getPrototypeOf(Console).call(this, options)); // Expose the name of this Transport on the prototype
_this.name = options.name || 'console';
_this.stderrLevels = _this._stringArrayToSet(options.stderrLevels);
_this.consoleWarnLevels = _this._stringArrayToSet(options.consoleWarnLevels);
_this.eol = options.eol || os.EOL;
_this.setMaxListeners(30);
return _this;
}
/**
* Core logging method exposed to Winston.
* @param {Object} info - TODO: add param description.
* @param {Function} callback - TODO: add param description.
* @returns {undefined}
*/
_createClass(Console, [{
key: "log",
value: function log(info, callback) {
var _this2 = this;
setImmediate(function () {
return _this2.emit('logged', info);
}); // Remark: what if there is no raw...?
if (this.stderrLevels[info[LEVEL]]) {
if (console._stderr) {
// Node.js maps `process.stderr` to `console._stderr`.
console._stderr.write("".concat(info[MESSAGE]).concat(this.eol));
} else {
// console.error adds a newline
console.error(info[MESSAGE]);
}
if (callback) {
callback(); // eslint-disable-line callback-return
}
return;
} else if (this.consoleWarnLevels[info[LEVEL]]) {
if (console._stderr) {
// Node.js maps `process.stderr` to `console._stderr`.
// in Node.js console.warn is an alias for console.error
console._stderr.write("".concat(info[MESSAGE]).concat(this.eol));
} else {
// console.warn adds a newline
console.warn(info[MESSAGE]);
}
if (callback) {
callback(); // eslint-disable-line callback-return
}
return;
}
if (console._stdout) {
// Node.js maps `process.stdout` to `console._stdout`.
console._stdout.write("".concat(info[MESSAGE]).concat(this.eol));
} else {
// console.log adds a newline.
console.log(info[MESSAGE]);
}
if (callback) {
callback(); // eslint-disable-line callback-return
}
}
/**
* Returns a Set-like object with strArray's elements as keys (each with the
* value true).
* @param {Array} strArray - Array of Set-elements as strings.
* @param {?string} [errMsg] - Custom error message thrown on invalid input.
* @returns {Object} - TODO: add return description.
* @private
*/
}, {
key: "_stringArrayToSet",
value: function _stringArrayToSet(strArray, errMsg) {
if (!strArray) return {};
errMsg = errMsg || 'Cannot make set from type other than Array of string elements';
if (!Array.isArray(strArray)) {
throw new Error(errMsg);
}
return strArray.reduce(function (set, el) {
if (typeof el !== 'string') {
throw new Error(errMsg);
}
set[el] = true;
return set;
}, {});
}
}]);
return Console;
}(TransportStream);

815
node_modules/winston/dist/winston/transports/file.js generated vendored Normal file
View File

@ -0,0 +1,815 @@
/* eslint-disable complexity,max-statements */
/**
* file.js: Transport for outputting to a local log file.
*
* (C) 2010 Charlie Robbins
* MIT LICENCE
*/
'use strict';
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
var fs = require('fs');
var path = require('path');
var asyncSeries = require('async/series');
var zlib = require('zlib');
var _require = require('triple-beam'),
MESSAGE = _require.MESSAGE;
var _require2 = require('readable-stream'),
Stream = _require2.Stream,
PassThrough = _require2.PassThrough;
var TransportStream = require('winston-transport');
var debug = require('diagnostics')('winston:file');
var os = require('os');
var tailFile = require('../tail-file');
/**
* Transport for outputting to a local log file.
* @type {File}
* @extends {TransportStream}
*/
module.exports =
/*#__PURE__*/
function (_TransportStream) {
_inherits(File, _TransportStream);
/**
* Constructor function for the File transport object responsible for
* persisting log messages and metadata to one or more files.
* @param {Object} options - Options for this instance.
*/
function File() {
var _this;
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
_classCallCheck(this, File);
_this = _possibleConstructorReturn(this, _getPrototypeOf(File).call(this, options)); // Expose the name of this Transport on the prototype.
_this.name = options.name || 'file'; // Helper function which throws an `Error` in the event that any of the
// rest of the arguments is present in `options`.
function throwIf(target) {
for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
args[_key - 1] = arguments[_key];
}
args.slice(1).forEach(function (name) {
if (options[name]) {
throw new Error("Cannot set ".concat(name, " and ").concat(target, " together"));
}
});
} // Setup the base stream that always gets piped to to handle buffering.
_this._stream = new PassThrough();
_this._stream.setMaxListeners(30); // Bind this context for listener methods.
_this._onError = _this._onError.bind(_assertThisInitialized(_assertThisInitialized(_this)));
if (options.filename || options.dirname) {
throwIf('filename or dirname', 'stream');
_this._basename = _this.filename = options.filename ? path.basename(options.filename) : 'winston.log';
_this.dirname = options.dirname || path.dirname(options.filename);
_this.options = options.options || {
flags: 'a'
};
} else if (options.stream) {
// eslint-disable-next-line no-console
console.warn('options.stream will be removed in winston@4. Use winston.transports.Stream');
throwIf('stream', 'filename', 'maxsize');
_this._dest = _this._stream.pipe(_this._setupStream(options.stream));
_this.dirname = path.dirname(_this._dest.path); // We need to listen for drain events when write() returns false. This
// can make node mad at times.
} else {
throw new Error('Cannot log to file without filename or stream.');
}
_this.maxsize = options.maxsize || null;
_this.rotationFormat = options.rotationFormat || false;
_this.zippedArchive = options.zippedArchive || false;
_this.maxFiles = options.maxFiles || null;
_this.eol = options.eol || os.EOL;
_this.tailable = options.tailable || false; // Internal state variables representing the number of files this instance
// has created and the current size (in bytes) of the current logfile.
_this._size = 0;
_this._pendingSize = 0;
_this._created = 0;
_this._drain = false;
_this._opening = false;
_this._ending = false;
if (_this.dirname) _this._createLogDirIfNotExist(_this.dirname);
_this.open();
return _this;
}
_createClass(File, [{
key: "finishIfEnding",
value: function finishIfEnding() {
var _this2 = this;
if (this._ending) {
if (this._opening) {
this.once('open', function () {
_this2._stream.once('finish', function () {
return _this2.emit('finish');
});
setImmediate(function () {
return _this2._stream.end();
});
});
} else {
this._stream.once('finish', function () {
return _this2.emit('finish');
});
setImmediate(function () {
return _this2._stream.end();
});
}
}
}
/**
* Core logging method exposed to Winston. Metadata is optional.
* @param {Object} info - TODO: add param description.
* @param {Function} callback - TODO: add param description.
* @returns {undefined}
*/
}, {
key: "log",
value: function log(info) {
var _this3 = this;
var callback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : function () {};
// Remark: (jcrugzz) What is necessary about this callback(null, true) now
// when thinking about 3.x? Should silent be handled in the base
// TransportStream _write method?
if (this.silent) {
callback();
return true;
} // Output stream buffer is full and has asked us to wait for the drain event
if (this._drain) {
this._stream.once('drain', function () {
_this3._drain = false;
_this3.log(info, callback);
});
return;
}
if (this._rotate) {
this._stream.once('rotate', function () {
_this3._rotate = false;
_this3.log(info, callback);
});
return;
} // Grab the raw string and append the expected EOL.
var output = "".concat(info[MESSAGE]).concat(this.eol);
var bytes = Buffer.byteLength(output); // After we have written to the PassThrough check to see if we need
// to rotate to the next file.
//
// Remark: This gets called too early and does not depict when data
// has been actually flushed to disk.
function logged() {
var _this4 = this;
this._size += bytes;
this._pendingSize -= bytes;
debug('logged %s %s', this._size, output);
this.emit('logged', info); // Do not attempt to rotate files while opening
if (this._opening) {
return;
} // Check to see if we need to end the stream and create a new one.
if (!this._needsNewFile()) {
return;
} // End the current stream, ensure it flushes and create a new one.
// This could potentially be optimized to not run a stat call but its
// the safest way since we are supporting `maxFiles`.
this._rotate = true;
this._endStream(function () {
return _this4._rotateFile();
});
} // Keep track of the pending bytes being written while files are opening
// in order to properly rotate the PassThrough this._stream when the file
// eventually does open.
this._pendingSize += bytes;
if (this._opening && !this.rotatedWhileOpening && this._needsNewFile(this._size + this._pendingSize)) {
this.rotatedWhileOpening = true;
}
var written = this._stream.write(output, logged.bind(this));
if (!written) {
this._drain = true;
this._stream.once('drain', function () {
_this3._drain = false;
callback();
});
} else {
callback(); // eslint-disable-line callback-return
}
debug('written', written, this._drain);
this.finishIfEnding();
return written;
}
/**
* Query the transport. Options object is optional.
* @param {Object} options - Loggly-like query options for this instance.
* @param {function} callback - Continuation to respond to when complete.
* TODO: Refactor me.
*/
}, {
key: "query",
value: function query(options, callback) {
if (typeof options === 'function') {
callback = options;
options = {};
}
options = normalizeQuery(options);
var file = path.join(this.dirname, this.filename);
var buff = '';
var results = [];
var row = 0;
var stream = fs.createReadStream(file, {
encoding: 'utf8'
});
stream.on('error', function (err) {
if (stream.readable) {
stream.destroy();
}
if (!callback) {
return;
}
return err.code !== 'ENOENT' ? callback(err) : callback(null, results);
});
stream.on('data', function (data) {
data = (buff + data).split(/\n+/);
var l = data.length - 1;
var i = 0;
for (; i < l; i++) {
if (!options.start || row >= options.start) {
add(data[i]);
}
row++;
}
buff = data[l];
});
stream.on('close', function () {
if (buff) {
add(buff, true);
}
if (options.order === 'desc') {
results = results.reverse();
} // eslint-disable-next-line callback-return
if (callback) callback(null, results);
});
function add(buff, attempt) {
try {
var log = JSON.parse(buff);
if (check(log)) {
push(log);
}
} catch (e) {
if (!attempt) {
stream.emit('error', e);
}
}
}
function push(log) {
if (options.rows && results.length >= options.rows && options.order !== 'desc') {
if (stream.readable) {
stream.destroy();
}
return;
}
if (options.fields) {
log = options.fields.reduce(function (obj, key) {
obj[key] = log[key];
return obj;
}, {});
}
if (options.order === 'desc') {
if (results.length >= options.rows) {
results.shift();
}
}
results.push(log);
}
function check(log) {
if (!log) {
return;
}
if (_typeof(log) !== 'object') {
return;
}
var time = new Date(log.timestamp);
if (options.from && time < options.from || options.until && time > options.until || options.level && options.level !== log.level) {
return;
}
return true;
}
function normalizeQuery(options) {
options = options || {}; // limit
options.rows = options.rows || options.limit || 10; // starting row offset
options.start = options.start || 0; // now
options.until = options.until || new Date();
if (_typeof(options.until) !== 'object') {
options.until = new Date(options.until);
} // now - 24
options.from = options.from || options.until - 24 * 60 * 60 * 1000;
if (_typeof(options.from) !== 'object') {
options.from = new Date(options.from);
} // 'asc' or 'desc'
options.order = options.order || 'desc'; // which fields to select
options.fields = options.fields;
return options;
}
}
/**
* Returns a log stream for this transport. Options object is optional.
* @param {Object} options - Stream options for this instance.
* @returns {Stream} - TODO: add return description.
* TODO: Refactor me.
*/
}, {
key: "stream",
value: function stream() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var file = path.join(this.dirname, this.filename);
var stream = new Stream();
var tail = {
file: file,
start: options.start
};
stream.destroy = tailFile(tail, function (err, line) {
if (err) {
return stream.emit('error', err);
}
try {
stream.emit('data', line);
line = JSON.parse(line);
stream.emit('log', line);
} catch (e) {
stream.emit('error', e);
}
});
return stream;
}
/**
* Checks to see the filesize of.
* @returns {undefined}
*/
}, {
key: "open",
value: function open() {
var _this5 = this;
// If we do not have a filename then we were passed a stream and
// don't need to keep track of size.
if (!this.filename) return;
if (this._opening) return;
this._opening = true; // Stat the target file to get the size and create the stream.
this.stat(function (err, size) {
if (err) {
return _this5.emit('error', err);
}
debug('stat done: %s { size: %s }', _this5.filename, size);
_this5._size = size;
_this5._dest = _this5._createStream(_this5._stream);
_this5._opening = false;
_this5.once('open', function () {
if (_this5._stream.eventNames().includes('rotate')) {
_this5._stream.emit('rotate');
} else {
_this5._rotate = false;
}
});
});
}
/**
* Stat the file and assess information in order to create the proper stream.
* @param {function} callback - TODO: add param description.
* @returns {undefined}
*/
}, {
key: "stat",
value: function stat(callback) {
var _this6 = this;
var target = this._getFile();
var fullpath = path.join(this.dirname, target);
fs.stat(fullpath, function (err, stat) {
if (err && err.code === 'ENOENT') {
debug('ENOENT ok', fullpath); // Update internally tracked filename with the new target name.
_this6.filename = target;
return callback(null, 0);
}
if (err) {
debug("err ".concat(err.code, " ").concat(fullpath));
return callback(err);
}
if (!stat || _this6._needsNewFile(stat.size)) {
// If `stats.size` is greater than the `maxsize` for this
// instance then try again.
return _this6._incFile(function () {
return _this6.stat(callback);
});
} // Once we have figured out what the filename is, set it
// and return the size.
_this6.filename = target;
callback(null, stat.size);
});
}
/**
* Closes the stream associated with this instance.
* @param {function} cb - TODO: add param description.
* @returns {undefined}
*/
}, {
key: "close",
value: function close(cb) {
var _this7 = this;
if (!this._stream) {
return;
}
this._stream.end(function () {
if (cb) {
cb(); // eslint-disable-line callback-return
}
_this7.emit('flush');
_this7.emit('closed');
});
}
/**
* TODO: add method description.
* @param {number} size - TODO: add param description.
* @returns {undefined}
*/
}, {
key: "_needsNewFile",
value: function _needsNewFile(size) {
size = size || this._size;
return this.maxsize && size >= this.maxsize;
}
/**
* TODO: add method description.
* @param {Error} err - TODO: add param description.
* @returns {undefined}
*/
}, {
key: "_onError",
value: function _onError(err) {
this.emit('error', err);
}
/**
* TODO: add method description.
* @param {Stream} stream - TODO: add param description.
* @returns {mixed} - TODO: add return description.
*/
}, {
key: "_setupStream",
value: function _setupStream(stream) {
stream.on('error', this._onError);
return stream;
}
/**
* TODO: add method description.
* @param {Stream} stream - TODO: add param description.
* @returns {mixed} - TODO: add return description.
*/
}, {
key: "_cleanupStream",
value: function _cleanupStream(stream) {
stream.removeListener('error', this._onError);
return stream;
}
/**
* TODO: add method description.
*/
}, {
key: "_rotateFile",
value: function _rotateFile() {
var _this8 = this;
this._incFile(function () {
return _this8.open();
});
}
/**
* Unpipe from the stream that has been marked as full and end it so it
* flushes to disk.
*
* @param {function} callback - Callback for when the current file has closed.
* @private
*/
}, {
key: "_endStream",
value: function _endStream() {
var _this9 = this;
var callback = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : function () {};
if (this._dest) {
this._stream.unpipe(this._dest);
this._dest.end(function () {
_this9._cleanupStream(_this9._dest);
callback();
});
} else {
callback(); // eslint-disable-line callback-return
}
}
/**
* Returns the WritableStream for the active file on this instance. If we
* should gzip the file then a zlib stream is returned.
*
* @param {ReadableStream} source  PassThrough to pipe to the file when open.
* @returns {WritableStream} Stream that writes to disk for the active file.
*/
}, {
key: "_createStream",
value: function _createStream(source) {
var _this10 = this;
var fullpath = path.join(this.dirname, this.filename);
debug('create stream start', fullpath, this.options);
var dest = fs.createWriteStream(fullpath, this.options) // TODO: What should we do with errors here?
.on('error', function (err) {
return debug(err);
}).on('close', function () {
return debug('close', dest.path, dest.bytesWritten);
}).on('open', function () {
debug('file open ok', fullpath);
_this10.emit('open', fullpath);
source.pipe(dest); // If rotation occured during the open operation then we immediately
// start writing to a new PassThrough, begin opening the next file
// and cleanup the previous source and dest once the source has drained.
if (_this10.rotatedWhileOpening) {
_this10._stream = new PassThrough();
_this10._stream.setMaxListeners(30);
_this10._rotateFile();
_this10.rotatedWhileOpening = false;
_this10._cleanupStream(dest);
source.end();
}
});
debug('create stream ok', fullpath);
if (this.zippedArchive) {
var gzip = zlib.createGzip();
gzip.pipe(dest);
return gzip;
}
return dest;
}
/**
* TODO: add method description.
* @param {function} callback - TODO: add param description.
* @returns {undefined}
*/
}, {
key: "_incFile",
value: function _incFile(callback) {
debug('_incFile', this.filename);
var ext = path.extname(this._basename);
var basename = path.basename(this._basename, ext);
if (!this.tailable) {
this._created += 1;
this._checkMaxFilesIncrementing(ext, basename, callback);
} else {
this._checkMaxFilesTailable(ext, basename, callback);
}
}
/**
* Gets the next filename to use for this instance in the case that log
* filesizes are being capped.
* @returns {string} - TODO: add return description.
* @private
*/
}, {
key: "_getFile",
value: function _getFile() {
var ext = path.extname(this._basename);
var basename = path.basename(this._basename, ext);
var isRotation = this.rotationFormat ? this.rotationFormat() : this._created; // Caveat emptor (indexzero): rotationFormat() was broken by design When
// combined with max files because the set of files to unlink is never
// stored.
var target = !this.tailable && this._created ? "".concat(basename).concat(isRotation).concat(ext) : "".concat(basename).concat(ext);
return this.zippedArchive && !this.tailable ? "".concat(target, ".gz") : target;
}
/**
* Increment the number of files created or checked by this instance.
* @param {mixed} ext - TODO: add param description.
* @param {mixed} basename - TODO: add param description.
* @param {mixed} callback - TODO: add param description.
* @returns {undefined}
* @private
*/
}, {
key: "_checkMaxFilesIncrementing",
value: function _checkMaxFilesIncrementing(ext, basename, callback) {
// Check for maxFiles option and delete file.
if (!this.maxFiles || this._created < this.maxFiles) {
return setImmediate(callback);
}
var oldest = this._created - this.maxFiles;
var isOldest = oldest !== 0 ? oldest : '';
var isZipped = this.zippedArchive ? '.gz' : '';
var filePath = "".concat(basename).concat(isOldest).concat(ext).concat(isZipped);
var target = path.join(this.dirname, filePath);
fs.unlink(target, callback);
}
/**
* Roll files forward based on integer, up to maxFiles. e.g. if base if
* file.log and it becomes oversized, roll to file1.log, and allow file.log
* to be re-used. If file is oversized again, roll file1.log to file2.log,
* roll file.log to file1.log, and so on.
* @param {mixed} ext - TODO: add param description.
* @param {mixed} basename - TODO: add param description.
* @param {mixed} callback - TODO: add param description.
* @returns {undefined}
* @private
*/
}, {
key: "_checkMaxFilesTailable",
value: function _checkMaxFilesTailable(ext, basename, callback) {
var _this12 = this;
var tasks = [];
if (!this.maxFiles) {
return;
} // const isZipped = this.zippedArchive ? '.gz' : '';
var isZipped = this.zippedArchive ? '.gz' : '';
for (var x = this.maxFiles - 1; x > 1; x--) {
tasks.push(function (i, cb) {
var _this11 = this;
var fileName = "".concat(basename).concat(i - 1).concat(ext).concat(isZipped);
var tmppath = path.join(this.dirname, fileName);
fs.exists(tmppath, function (exists) {
if (!exists) {
return cb(null);
}
fileName = "".concat(basename).concat(i).concat(ext).concat(isZipped);
fs.rename(tmppath, path.join(_this11.dirname, fileName), cb);
});
}.bind(this, x));
}
asyncSeries(tasks, function () {
fs.rename(path.join(_this12.dirname, "".concat(basename).concat(ext)), path.join(_this12.dirname, "".concat(basename, "1").concat(ext).concat(isZipped)), callback);
});
}
}, {
key: "_createLogDirIfNotExist",
value: function _createLogDirIfNotExist(dirPath) {
/* eslint-disable no-sync */
if (!fs.existsSync(dirPath)) {
fs.mkdirSync(dirPath, {
recursive: true
});
}
/* eslint-enable no-sync */
}
}]);
return File;
}(TransportStream);

247
node_modules/winston/dist/winston/transports/http.js generated vendored Normal file
View File

@ -0,0 +1,247 @@
/**
* http.js: Transport for outputting to a json-rpcserver.
*
* (C) 2010 Charlie Robbins
* MIT LICENCE
*/
'use strict';
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
var http = require('http');
var https = require('https');
var _require = require('readable-stream'),
Stream = _require.Stream;
var TransportStream = require('winston-transport');
/**
* Transport for outputting to a json-rpc server.
* @type {Stream}
* @extends {TransportStream}
*/
module.exports =
/*#__PURE__*/
function (_TransportStream) {
_inherits(Http, _TransportStream);
/**
* Constructor function for the Http transport object responsible for
* persisting log messages and metadata to a terminal or TTY.
* @param {!Object} [options={}] - Options for this instance.
*/
function Http() {
var _this;
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
_classCallCheck(this, Http);
_this = _possibleConstructorReturn(this, _getPrototypeOf(Http).call(this, options));
_this.name = options.name || 'http';
_this.ssl = !!options.ssl;
_this.host = options.host || 'localhost';
_this.port = options.port;
_this.auth = options.auth;
_this.path = options.path || '';
_this.agent = options.agent;
_this.headers = options.headers || {};
_this.headers['content-type'] = 'application/json';
if (!_this.port) {
_this.port = _this.ssl ? 443 : 80;
}
return _this;
}
/**
* Core logging method exposed to Winston.
* @param {Object} info - TODO: add param description.
* @param {function} callback - TODO: add param description.
* @returns {undefined}
*/
_createClass(Http, [{
key: "log",
value: function log(info, callback) {
var _this2 = this;
this._request(info, function (err, res) {
if (res && res.statusCode !== 200) {
err = new Error("Invalid HTTP Status Code: ".concat(res.statusCode));
}
if (err) {
_this2.emit('warn', err);
} else {
_this2.emit('logged', info);
}
}); // Remark: (jcrugzz) Fire and forget here so requests dont cause buffering
// and block more requests from happening?
if (callback) {
setImmediate(callback);
}
}
/**
* Query the transport. Options object is optional.
* @param {Object} options - Loggly-like query options for this instance.
* @param {function} callback - Continuation to respond to when complete.
* @returns {undefined}
*/
}, {
key: "query",
value: function query(options, callback) {
if (typeof options === 'function') {
callback = options;
options = {};
}
options = {
method: 'query',
params: this.normalizeQuery(options)
};
if (options.params.path) {
options.path = options.params.path;
delete options.params.path;
}
if (options.params.auth) {
options.auth = options.params.auth;
delete options.params.auth;
}
this._request(options, function (err, res, body) {
if (res && res.statusCode !== 200) {
err = new Error("Invalid HTTP Status Code: ".concat(res.statusCode));
}
if (err) {
return callback(err);
}
if (typeof body === 'string') {
try {
body = JSON.parse(body);
} catch (e) {
return callback(e);
}
}
callback(null, body);
});
}
/**
* Returns a log stream for this transport. Options object is optional.
* @param {Object} options - Stream options for this instance.
* @returns {Stream} - TODO: add return description
*/
}, {
key: "stream",
value: function stream() {
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
var stream = new Stream();
options = {
method: 'stream',
params: options
};
if (options.params.path) {
options.path = options.params.path;
delete options.params.path;
}
if (options.params.auth) {
options.auth = options.params.auth;
delete options.params.auth;
}
var buff = '';
var req = this._request(options);
stream.destroy = function () {
return req.destroy();
};
req.on('data', function (data) {
data = (buff + data).split(/\n+/);
var l = data.length - 1;
var i = 0;
for (; i < l; i++) {
try {
stream.emit('log', JSON.parse(data[i]));
} catch (e) {
stream.emit('error', e);
}
}
buff = data[l];
});
req.on('error', function (err) {
return stream.emit('error', err);
});
return stream;
}
/**
* Make a request to a winstond server or any http server which can
* handle json-rpc.
* @param {function} options - Options to sent the request.
* @param {function} callback - Continuation to respond to when complete.
*/
}, {
key: "_request",
value: function _request(options, callback) {
options = options || {};
var auth = options.auth || this.auth;
var path = options.path || this.path || '';
delete options.auth;
delete options.path; // Prepare options for outgoing HTTP request
var req = (this.ssl ? https : http).request({
method: 'POST',
host: this.host,
port: this.port,
path: "/".concat(path.replace(/^\//, '')),
headers: this.headers,
auth: auth ? "".concat(auth.username, ":").concat(auth.password) : '',
agent: this.agent
});
req.on('error', callback);
req.on('response', function (res) {
return res.on('end', function () {
return callback(null, res);
}).resume();
});
req.end(Buffer.from(JSON.stringify(options), 'utf8'));
}
}]);
return Http;
}(TransportStream);

55
node_modules/winston/dist/winston/transports/index.js generated vendored Normal file
View File

@ -0,0 +1,55 @@
/**
* transports.js: Set of all transports Winston knows about.
*
* (C) 2010 Charlie Robbins
* MIT LICENCE
*/
'use strict';
/**
* TODO: add property description.
* @type {Console}
*/
Object.defineProperty(exports, 'Console', {
configurable: true,
enumerable: true,
get: function get() {
return require('./console');
}
});
/**
* TODO: add property description.
* @type {File}
*/
Object.defineProperty(exports, 'File', {
configurable: true,
enumerable: true,
get: function get() {
return require('./file');
}
});
/**
* TODO: add property description.
* @type {Http}
*/
Object.defineProperty(exports, 'Http', {
configurable: true,
enumerable: true,
get: function get() {
return require('./http');
}
});
/**
* TODO: add property description.
* @type {Stream}
*/
Object.defineProperty(exports, 'Stream', {
configurable: true,
enumerable: true,
get: function get() {
return require('./stream');
}
});

113
node_modules/winston/dist/winston/transports/stream.js generated vendored Normal file
View File

@ -0,0 +1,113 @@
/**
* stream.js: Transport for outputting to any arbitrary stream.
*
* (C) 2010 Charlie Robbins
* MIT LICENCE
*/
'use strict';
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
var isStream = require('is-stream');
var _require = require('triple-beam'),
MESSAGE = _require.MESSAGE;
var os = require('os');
var TransportStream = require('winston-transport');
/**
* Transport for outputting to any arbitrary stream.
* @type {Stream}
* @extends {TransportStream}
*/
module.exports =
/*#__PURE__*/
function (_TransportStream) {
_inherits(Stream, _TransportStream);
/**
* Constructor function for the Console transport object responsible for
* persisting log messages and metadata to a terminal or TTY.
* @param {!Object} [options={}] - Options for this instance.
*/
function Stream() {
var _this;
var options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
_classCallCheck(this, Stream);
_this = _possibleConstructorReturn(this, _getPrototypeOf(Stream).call(this, options));
if (!options.stream || !isStream(options.stream)) {
throw new Error('options.stream is required.');
} // We need to listen for drain events when write() returns false. This can
// make node mad at times.
_this._stream = options.stream;
_this._stream.setMaxListeners(Infinity);
_this.isObjectMode = options.stream._writableState.objectMode;
_this.eol = options.eol || os.EOL;
return _this;
}
/**
* Core logging method exposed to Winston.
* @param {Object} info - TODO: add param description.
* @param {Function} callback - TODO: add param description.
* @returns {undefined}
*/
_createClass(Stream, [{
key: "log",
value: function log(info, callback) {
var _this2 = this;
setImmediate(function () {
return _this2.emit('logged', info);
});
if (this.isObjectMode) {
this._stream.write(info);
if (callback) {
callback(); // eslint-disable-line callback-return
}
return;
}
this._stream.write("".concat(info[MESSAGE]).concat(this.eol));
if (callback) {
callback(); // eslint-disable-line callback-return
}
return;
}
}]);
return Stream;
}(TransportStream);