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

41 lines (40 loc) 1.48 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.Filter = void 0; const 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') * ``` */ class Filter extends transform_js_1.Transform { /** Create our instance and apply our configuraiton options. */ constructor(opts) { super(); /** * 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; } /** Retain only log entries that are equal to or less than the specified filter level. */ format(entry) { return entry.levelNumber <= this.filterLevel ? entry : null; } } exports.Filter = Filter; exports.default = Filter;