UNPKG

caterpillar

Version:

Caterpillar is the ultimate logging system for Deno, Node.js, and Web Browsers. Log levels are implemented to the RFC standard. Log entries can be filtered and piped to various streams, including coloured output to the terminal, the browser's console, and

59 lines (58 loc) 2.4 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); Object.defineProperty(exports, "__esModule", { value: true }); exports.Filter = void 0; var transform_js_1 = require("../transform.js"); /** * Caterpillar Filter Transform. * Filters the log entries, keeping only those equal to or below the specified `filterLevel`. * @example * ``` javascript * import { Logger, Filter } from 'caterpillar' * const logger = new Logger() * const filter = new Filter({ filterLevel: 6 }) * logger.pipe(filter).pipe(process.stdout) * logger.log('info', 'this will be outputted') * logger.log('debug', 'this will be ignored') * filter.filterLevel = 5 * logger.log('info', 'now even this will be ignored') * logger.log('note', 'but not this') * ``` */ var Filter = /** @class */ (function (_super) { __extends(Filter, _super); /** Create our instance and apply our configuraiton options. */ function Filter(opts) { var _this = _super.call(this) || this; /** * Only display entries that have a log level below or equal to this number. * Defaults to `6`, which by default is the info log level. */ _this.filterLevel = 6; // options if ((opts === null || opts === void 0 ? void 0 : opts.filterLevel) != null) _this.filterLevel = opts.filterLevel; return _this; } /** Retain only log entries that are equal to or less than the specified filter level. */ Filter.prototype.format = function (entry) { return entry.levelNumber <= this.filterLevel ? entry : null; }; return Filter; }(transform_js_1.Transform)); exports.Filter = Filter; exports.default = Filter;