UNPKG

ethstats-cli

Version:
129 lines (106 loc) 4.85 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _chalk = _interopRequireDefault(require("chalk")); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: 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; } var Logger = /*#__PURE__*/ function () { function Logger(options) { _classCallCheck(this, Logger); options = options || {}; this.showDateTime = options.showDateTime === undefined ? true : options.showDateTime; this.showInfos = options.showInfos === undefined ? true : options.showInfos; this.showWarnings = options.showWarnings === undefined ? true : options.showWarnings; this.showErrors = options.showErrors === undefined ? true : options.showErrors; this.showDebugs = options.showDebugs === undefined ? true : options.showDebugs; this.chalk = _chalk.default; } _createClass(Logger, [{ key: "_log", value: function _log(type, string) { var beginWithNewLine = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; var processExit = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : false; var dateTime = new Date().toISOString().replace('T', ' ').replace('Z', ''); var newLine = beginWithNewLine ? '\n' : ''; var resultString = "".concat(newLine).concat(this.showDateTime ? dateTime + ' - ' : '', "%LOG-TYPE%: ").concat(string); switch (type) { case 'echo': console.log(string); break; case 'info': console.log(this.chalk.white(resultString.replace('%LOG-TYPE%', 'INFO'))); break; case 'debug': console.log(this.chalk.cyan(resultString.replace('%LOG-TYPE%', 'DEBUG'))); break; case 'warning': console.log(this.chalk.yellow(resultString.replace('%LOG-TYPE%', 'WARNING'))); break; case 'error': console.log(this.chalk.red(resultString.replace('%LOG-TYPE%', 'ERROR'))); break; default: console.log('Unknown log type'); break; } if (processExit) { process.exit(type === 'error' ? 1 : 0); } } }, { key: "echo", value: function echo(string) { var beginWithNewLine = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; var processExit = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; if (this.showInfos) { this._log('info', string, beginWithNewLine, processExit); } else { this._log('echo', string); } } }, { key: "info", value: function info(string) { var beginWithNewLine = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; var processExit = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; if (this.showInfos) { this._log('info', string, beginWithNewLine, processExit); } } }, { key: "debug", value: function debug(string) { var beginWithNewLine = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; var processExit = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; if (this.showDebugs) { this._log('debug', string, beginWithNewLine, processExit); } } }, { key: "warning", value: function warning(string) { var beginWithNewLine = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; var processExit = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; if (this.showWarnings) { this._log('warning', string, beginWithNewLine, processExit); } } }, { key: "error", value: function error(string) { var beginWithNewLine = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : false; var processExit = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : false; if (this.showErrors) { this._log('error', string, beginWithNewLine, processExit); } } }]); return Logger; }(); exports.default = Logger;