UNPKG

@nsalaun/ng-logger

Version:
239 lines (228 loc) 9 kB
(function (global, factory) { typeof exports === 'object' && typeof module !== 'undefined' ? factory(exports, require('@angular/core')) : typeof define === 'function' && define.amd ? define('@nsalaun/ng-logger', ['exports', '@angular/core'], factory) : (global = typeof globalThis !== 'undefined' ? globalThis : global || self, factory((global.nsalaun = global.nsalaun || {}, global.nsalaun['ng-logger'] = {}), global.ng.core)); }(this, (function (exports, i0) { 'use strict'; function _interopNamespace(e) { if (e && e.__esModule) return e; var n = Object.create(null); if (e) { Object.keys(e).forEach(function (k) { if (k !== 'default') { var d = Object.getOwnPropertyDescriptor(e, k); Object.defineProperty(n, k, d.get ? d : { enumerable: true, get: function () { return e[k]; } }); } }); } n['default'] = e; return Object.freeze(n); } var i0__namespace = /*#__PURE__*/_interopNamespace(i0); /** * @license * Copyright Noémi Salaün All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://github.com/noemi-salaun/ng-logger/blob/master/LICENSE */ /** * Created by Noémi Salaün on 09/17/2016. */ /** * The available log levels. */ exports.Level = void 0; (function (Level) { Level[Level["OFF"] = 0] = "OFF"; Level[Level["ERROR"] = 1] = "ERROR"; Level[Level["WARN"] = 2] = "WARN"; Level[Level["INFO"] = 3] = "INFO"; Level[Level["DEBUG"] = 4] = "DEBUG"; Level[Level["LOG"] = 5] = "LOG"; })(exports.Level || (exports.Level = {})); /** * @license * Copyright Noémi Salaün All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://github.com/noemi-salaun/ng-logger/blob/master/LICENSE */ /** * Created by Noémi Salaün on 09/17/2016. */ /** * The token to provide the log {@link Level}. */ var LOGGER_LEVEL = new i0.InjectionToken('LoggerLevel'); /** * A logger service that provide the same functions as {@link console}. * The logger is binded to the console, so the Web Console shows the correct file and line number of the original call. */ var Logger = /** @class */ (function () { function Logger(level) { this._level = level; // console.log if (this._level >= exports.Level.LOG && console && console.log) { this.log = console.log.bind(console); } else { this.log = function () { // Nothing }; } // console.debug if (this._level >= exports.Level.DEBUG && console && console.debug) { this.debug = console.debug.bind(console); } else { this.debug = function () { // Nothing }; } // console.info if (this._level >= exports.Level.INFO && console && console.info) { this.info = console.info.bind(console); } else { this.info = function () { // Nothing }; } // console.warn if (this._level >= exports.Level.WARN && console && console.warn) { this.warn = console.warn.bind(console); } else { this.warn = function () { // Nothing }; } // console.error if (this._level >= exports.Level.ERROR && console && console.error) { this.error = console.error.bind(console); } else { this.error = function () { // Nothing }; } // console.group if (this._level > exports.Level.OFF && console && console.group) { this.group = console.group.bind(console); } else { this.group = function () { // Nothing }; } // console.groupCollapsed if (this._level > exports.Level.OFF && console && console.groupCollapsed) { this.groupCollapsed = console.groupCollapsed.bind(console); } else { this.groupCollapsed = function () { // Nothing }; } // console.groupEnd if (this._level > exports.Level.OFF && console && console.groupEnd) { this.groupEnd = console.groupEnd.bind(console); } else { this.groupEnd = function () { // Nothing }; } // console.time if (this._level >= exports.Level.DEBUG && console && console.time) { this.time = console.time.bind(console); } else { this.time = function () { // Nothing }; } // console.timeEnd if (this._level >= exports.Level.DEBUG && console && console.timeEnd) { this.timeEnd = console.timeEnd.bind(console); } else { this.timeEnd = function () { // Nothing }; } } Object.defineProperty(Logger.prototype, "level", { /** * Returns the log level. */ get: function () { return this._level; }, enumerable: false, configurable: true }); return Logger; }()); Logger.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: Logger, deps: [{ token: LOGGER_LEVEL }], target: i0__namespace.ɵɵFactoryTarget.Injectable }); Logger.ɵprov = i0__namespace.ɵɵngDeclareInjectable({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: Logger }); i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: Logger, decorators: [{ type: i0.Injectable }], ctorParameters: function () { return [{ type: exports.Level, decorators: [{ type: i0.Inject, args: [LOGGER_LEVEL] }] }]; } }); /** * @license * Copyright Noémi Salaün All Rights Reserved. * * Use of this source code is governed by an MIT-style license that can be * found in the LICENSE file at https://github.com/noemi-salaun/ng-logger/blob/master/LICENSE */ /** * Created by Noémi Salaün on 09/17/2016. */ var NgLoggerModule = /** @class */ (function () { function NgLoggerModule() { } /** * Provide the {@link Logger} with the given log {@link Level}. * @param level The log level. */ NgLoggerModule.forRoot = function (level) { if (level === void 0) { level = exports.Level.LOG; } return { ngModule: NgLoggerModule, providers: [ Logger, { provide: LOGGER_LEVEL, useValue: level }, ], }; }; return NgLoggerModule; }()); NgLoggerModule.ɵfac = i0__namespace.ɵɵngDeclareFactory({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: NgLoggerModule, deps: [], target: i0__namespace.ɵɵFactoryTarget.NgModule }); NgLoggerModule.ɵmod = i0__namespace.ɵɵngDeclareNgModule({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: NgLoggerModule }); NgLoggerModule.ɵinj = i0__namespace.ɵɵngDeclareInjector({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: NgLoggerModule }); i0__namespace.ɵɵngDeclareClassMetadata({ minVersion: "12.0.0", version: "12.0.5", ngImport: i0__namespace, type: NgLoggerModule, decorators: [{ type: i0.NgModule }] }); /* * Public API Surface of ng-logger */ /** * Generated bundle index. Do not edit. */ exports.LOGGER_LEVEL = LOGGER_LEVEL; exports.Logger = Logger; exports.NgLoggerModule = NgLoggerModule; Object.defineProperty(exports, '__esModule', { value: true }); }))); //# sourceMappingURL=nsalaun-ng-logger.umd.js.map