UNPKG

nativescript

Version:

Command-line interface for building NativeScript projects

30 lines (29 loc) 1.04 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.configure = configure; const constants_1 = require("../../../constants"); function emitAppender(layout, emitter) { const appender = (loggingEvent) => { emitter.emit(constants_1.EMIT_APPENDER_EVENT_NAME, { loggingEvent, formattedMessage: layout(loggingEvent), }); }; appender.shutdown = () => { emitter.removeAllListeners(constants_1.EMIT_APPENDER_EVENT_NAME); }; return appender; } function configure(config, layouts) { if (!config.emitter) { throw new Error("Emitter must be passed to emit-appender"); } if (!config.emitter.emit || typeof config.emitter.emit !== "function") { throw new Error("The passed emitter must be instance of EventEmitter"); } let layout = layouts.messagePassThroughLayout; if (config.layout) { layout = layouts.layout(config.layout.type, config.layout); } return emitAppender(layout, config.emitter); }