UNPKG

@livy/logger

Version:

A Monolog-inspired logging library for Node.js

43 lines (42 loc) 1.38 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MixedLogger = void 0; const is_sync_handler_interface_1 = require("@livy/util/lib/handlers/is-sync-handler-interface"); const abstract_logger_1 = require("./abstract-logger"); /** * A mixed sync/async logger implementation * * It executes asynchronous handlers but does not await their results nor does it * respect their bubbling behavior or handle their errors */ class MixedLogger extends abstract_logger_1.AbstractLogger { /** * @inheritdoc */ withName(name) { return new MixedLogger(name, { handlers: this._handlers, processors: this._processors, timezone: this._timezone }); } /** * @inheritdoc */ runHandlers(record) { for (const handler of [...this._handlers].reverse()) { if ((0, is_sync_handler_interface_1.isSyncHandlerInterface)(handler)) { const result = handler.handleSync({ ...record }); if (result === true) { break; } } else { handler.handle({ ...record }).catch(error => { console.warn('Asynchronous handler failed to execute: %o', error); }); } } } } exports.MixedLogger = MixedLogger;