UNPKG

@livy/logger

Version:

A Monolog-inspired logging library for Node.js

43 lines (42 loc) 1.39 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SyncLogger = void 0; const gated_set_1 = require("@livy/util/lib/gated-set"); const is_sync_handler_interface_1 = require("@livy/util/lib/handlers/is-sync-handler-interface"); const abstract_logger_1 = require("./abstract-logger"); /** * A synchrous logger implementation which throws * on any attempt to add asynchronous functionality */ class SyncLogger extends abstract_logger_1.AbstractLogger { constructor(name, options) { super(name, options); this._handlers = new gated_set_1.GatedSet(handler => { if (!(0, is_sync_handler_interface_1.isSyncHandlerInterface)(handler)) { throw new Error('Invalid asynchronous handler in synchronous logger instance'); } }, [...this._handlers]); } /** * @inheritdoc */ withName(name) { return new SyncLogger(name, { handlers: this._handlers, processors: this._processors, timezone: this._timezone }); } /** * @inheritdoc */ runHandlers(record) { for (const handler of [...this._handlers].reverse()) { const result = handler.handleSync({ ...record }); if (result === true) { break; } } } } exports.SyncLogger = SyncLogger;