UNPKG

jaysonic

Version:

A feature rich JSON-RPC 1.0/2.0 compliant client and server library

66 lines (54 loc) 1.89 kB
"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 Logger = /*#__PURE__*/function () { /** * Singleton logging class to provide custom logger for library. * * Define the new logger at the top of the program, before instantiating * any new client or server classes. * * @returns instance of `Logger` */ function Logger() { _classCallCheck(this, Logger); if (Logger._instance) { return Logger._instance; } Logger._instance = this; this.log = console; } /** * Overwrite `Logger.log`, default `console`, which is used for * messages within the library * * @param {object} newLogger Object to overwrite `console` logging */ _createClass(Logger, [{ key: "setLogger", value: function setLogger(newLogger) { this.log = newLogger; } /** * * @returns `Logger.log` */ }, { key: "getLogger", value: function getLogger() { return new Logger().getInstance().log; } /** * * @returns instance of `Logger` */ }, { key: "getInstance", value: function getInstance() { return Logger._instance || new Logger(); } }]); return Logger; }(); module.exports = new Logger();