UNPKG

diffusion

Version:

Diffusion JavaScript client

88 lines (87 loc) 2.6 kB
"use strict"; /** * @module Util.Logger * * @brief Verbose logging output */ var __values = (this && this.__values) || function(o) { var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0; if (m) return m.call(o); if (o && typeof o.length === "number") return { next: function () { if (o && i >= o.length) o = void 0; return { value: o && o[i++], done: !o }; } }; throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined."); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.setLevel = exports.create = exports.LoggingLevel = void 0; var logger = require("loglevel"); /** * An enum for the available logging functions * * This is identical to {@link LogLevel} but without the `silent` value */ var LoggingLevel; (function (LoggingLevel) { LoggingLevel["trace"] = "trace"; LoggingLevel["debug"] = "debug"; LoggingLevel["info"] = "info"; LoggingLevel["warn"] = "warn"; LoggingLevel["error"] = "error"; })(LoggingLevel = exports.LoggingLevel || (exports.LoggingLevel = {})); /** * Verbose logging output * * Adds date, level information and prfix information to logging output * * @param level the logging level * @param prefix the prefix * @return a logging function that writes verbose output */ function log(level, prefix) { var c = '|' + level.toUpperCase() + '|' + prefix + '|'; var now = function () { return (new Date()); }; return function (msg, arg) { if (arg) { logger[level](now() + c + msg, arg); } else { logger[level](now() + c + msg); } }; } /** * Create a {@link Logger} with a given prefix * * @param prefix the prefix * @return a newly created {@link Logger} that contains a writer for each * log level */ function create(prefix) { var e_1, _a; var l = {}; try { for (var _b = __values(Object.keys(LoggingLevel)), _c = _b.next(); !_c.done; _c = _b.next()) { var level = _c.value; l[level] = log(level, prefix); } } catch (e_1_1) { e_1 = { error: e_1_1 }; } finally { try { if (_c && !_c.done && (_a = _b.return)) _a.call(_b); } finally { if (e_1) throw e_1.error; } } return l; } exports.create = create; /** * Disables logging below the given level. * * Export is forwarded from `loglevel.setLevel`. * @see https://www.npmjs.com/package/loglevel */ exports.setLevel = logger.setLevel;