UNPKG

ng2-logger

Version:

isomorphic logger for browser/server in typescript

133 lines 5.54 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const level_1 = require("./level"); const display_1 = require("./display"); const include_1 = require("./include"); class Logger { constructor(name, color, developmentMode, allowed, isMuted, fixedWidth, display) { this.name = name; this.color = color; this.developmentMode = developmentMode; this.allowed = allowed; this.isMuted = isMuted; this.fixedWidth = fixedWidth; this.display = display; /** @deprecated Use data(...) * @see data */ this.d = (name, ...data) => this._data(name, data); /** @deprecated Use error(...) * @see error */ this.er = (name, ...data) => this._error(name, data); /** @deprecated Use info(...) * @see info */ this.i = (name, ...data) => this._info(name, data); /** @deprecated Use warn(...) * @see warn */ this.w = (name, ...data) => this._warn(name, data); /** * Logs message and data with the level=data * @param message The message * @param otherParams Additional parameters */ this.data = (message, ...otherParams) => { return this._data(message, otherParams); }; /** * Logs message and data with the level=error * @param message The message * @param otherParams Additional parameters */ this.error = (message, ...otherParams) => this._error(message, otherParams); /** * Logs message and data with the level=info * @param message The message * @param otherParams Additional parameters */ this.info = (message, ...otherParams) => this._info(message, otherParams); /** * Logs message and data with the level=warn * @param message The message * @param otherParams Additional parameters */ this.warn = (message, ...otherParams) => this._warn(message, otherParams); } _data(name, ...data) { if (this.allowed.length >= 1 && include_1.contain(this.allowed, level_1.Level.__NOTHING) && !include_1.contain(this.allowed, level_1.Level.DATA)) return this; if (Logger.isProductionMode) return this; if (this.display !== undefined) this.display(name, data, level_1.Level.DATA, this.name); else if (this.allowed.length === 0 || include_1.contain(this.allowed, level_1.Level.DATA)) { display_1.Display.msg.apply(undefined, [name, ...data, this.name, this.color, level_1.Level.DATA, this.fixedWidth]); } return this; } _error(name, ...data) { if (this.allowed.length >= 1 && include_1.contain(this.allowed, level_1.Level.__NOTHING) && !include_1.contain(this.allowed, level_1.Level.ERROR)) return this; if (Logger.isProductionMode) return this; if (this.display !== undefined) this.display(name, data, level_1.Level.ERROR, this.name); else if (this.allowed.length === 0 || include_1.contain(this.allowed, level_1.Level.ERROR)) { display_1.Display.msg.apply(undefined, [name, ...data, this.name, this.color, level_1.Level.ERROR, this.fixedWidth]); } return this; } _info(name, ...data) { if (this.allowed.length >= 1 && include_1.contain(this.allowed, level_1.Level.__NOTHING) && !include_1.contain(this.allowed, level_1.Level.INFO)) return this; if (Logger.isProductionMode) return this; if (this.display !== undefined) this.display(name, data, level_1.Level.INFO, this.name); else if (this.allowed.length === 0 || include_1.contain(this.allowed, level_1.Level.INFO)) { display_1.Display.msg.apply(undefined, [name, ...data, this.name, this.color, level_1.Level.INFO, this.fixedWidth]); } return this; } _warn(name, ...data) { if (this.allowed.length >= 1 && include_1.contain(this.allowed, level_1.Level.__NOTHING) && !include_1.contain(this.allowed, level_1.Level.WARN)) return this; if (Logger.isProductionMode) return this; if (this.display !== undefined) this.display(name, data, level_1.Level.WARN, this.name); else if (this.allowed.length === 0 || include_1.contain(this.allowed, level_1.Level.WARN)) { display_1.Display.msg.apply(undefined, [name, ...data, this.name, this.color, level_1.Level.WARN, this.fixedWidth]); } return this; } _logMessage(name, level, ...data) { if (this.isMuted) return this; if (this.allowed.length >= 1 && include_1.contain(this.allowed, level) && !include_1.contain(this.allowed, level)) return this; if (Logger.isProductionMode) return this; if (this.display !== undefined) this.display(name, data, level, this.name); else if (this.allowed.length === 0 || include_1.contain(this.allowed, level)) { display_1.Display.msg(name, data, this.name, this.color, level, this.fixedWidth); } return this; } level(l) { this._level = l; return this; } mute() { this.isMuted = true; } } Logger.isProductionMode = false; exports.Logger = Logger; //# sourceMappingURL=logger.js.map