"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _nullishCoalesce(lhs, rhsFn) { if (lhs != null) { return lhs; } else { return rhsFn(); } }// src/BaseTransport.ts var _shared = require('@loglayer/shared'); var BaseTransport = class { /** * An identifier for the transport. If not defined, a random one will be generated. */ /** * Instance of the logger library */ /** * If false, the transport will not send logs to the logger. */ /** * If true, the transport will log to the console for debugging purposes */ constructor(config) { this.id = _nullishCoalesce(config.id, () => ( (/* @__PURE__ */ new Date()).getTime().toString() + Math.random().toString())); this.logger = config.logger; this.enabled = _nullishCoalesce(config.enabled, () => ( true)); this.consoleDebug = _nullishCoalesce(config.consoleDebug, () => ( false)); } /** * LogLayer calls this to send logs to the transport */ _sendToLogger(params) { if (!this.enabled) { return; } const messages = this.shipToLogger(params); if (this.consoleDebug) { switch (params.logLevel) { case _shared.LogLevel.info: console.info(...messages); break; case _shared.LogLevel.warn: console.warn(...messages); break; case _shared.LogLevel.error: console.error(...messages); break; case _shared.LogLevel.trace: console.debug(...messages); break; case _shared.LogLevel.debug: console.debug(...messages); break; case _shared.LogLevel.fatal: console.debug(...messages); break; default: console.log(...messages); } } } /** * Returns the logger instance attached to the transport */ getLoggerInstance() { return this.logger; } }; // src/types.ts var LogLevelPriority = { [_shared.LogLevel.trace]: 0, [_shared.LogLevel.debug]: 1, [_shared.LogLevel.info]: 2, [_shared.LogLevel.warn]: 3, [_shared.LogLevel.error]: 4, [_shared.LogLevel.fatal]: 5 }; // src/index.ts // src/test-utils.ts function testTransportOutput(label, logLayerInstance) { console.log(` ===== Start Livetest for: ${label} =====`); console.log("\n===== info() ===="); logLayerInstance.info("info message"); console.log("\n===== warn() ===="); logLayerInstance.warn("warn message"); console.log("\n===== error() ===="); logLayerInstance.error("error message"); console.log("\n===== debug() ===="); logLayerInstance.debug("debug message"); console.log("\n===== trace() ===="); logLayerInstance.trace("trace message"); console.log("\n===== fatal() ===="); logLayerInstance.fatal("fatal message"); console.log("\n===== withMetadata() ===="); logLayerInstance.withMetadata({ test: "metadata", test2: "metadata2" }).trace("trace message with metadata"); console.log("\n===== withError() ===="); logLayerInstance.withError(new Error("error object")).trace("trace message with error"); console.log("\n===== withError() + withMetadata() ===="); logLayerInstance.withMetadata({ test: "metadata", test2: "metadata2", nested: { data: "nested data" } }).withError(new Error("error object")).error("error message with metadata and error instance"); console.log("\n===== onlyError() ===="); logLayerInstance.errorOnly(new Error("error message")); console.log("\n===== onlyMetadata() ===="); logLayerInstance.metadataOnly({ only: "metadata", arrayData: [1, 2, 3] }); console.log("\n===== withContext() ===="); logLayerInstance.withContext({ test: "data" }); logLayerInstance.info("context data"); console.log(` ===== End Livetest for: ${label} =====`); } // src/LoggerlessTransport.ts var LoggerlessTransport = class { /** * An identifier for the transport. If not defined, a random one will be generated. */ /** * If false, the transport will not send logs to the logger. */ /** * Minimum log level to process. Defaults to "trace". */ /** * If true, the transport will log to the console for debugging purposes */ constructor(config) { this.id = (/* @__PURE__ */ new Date()).getTime().toString() + Math.random().toString(); this.enabled = _nullishCoalesce(config.enabled, () => ( true)); this.consoleDebug = _nullishCoalesce(config.consoleDebug, () => ( false)); this.level = _nullishCoalesce(config.level, () => ( "trace")); } /** * LogLayer calls this to send logs to the transport */ _sendToLogger(params) { if (!this.enabled) { return; } if (LogLevelPriority[params.logLevel] < LogLevelPriority[this.level]) { return; } const messages = this.shipToLogger(params); if (this.consoleDebug) { switch (params.logLevel) { case _shared.LogLevel.info: console.info(...messages); break; case _shared.LogLevel.warn: console.warn(...messages); break; case _shared.LogLevel.error: console.error(...messages); break; case _shared.LogLevel.trace: console.debug(...messages); break; case _shared.LogLevel.debug: console.debug(...messages); break; case _shared.LogLevel.fatal: console.debug(...messages); break; default: console.log(...messages); } } } /** * Returns the logger instance attached to the transport */ getLoggerInstance() { throw new Error("This transport does not have a logger instance"); } }; exports.BaseTransport = BaseTransport; exports.LogLevel = _shared.LogLevel; exports.LogLevelPriority = LogLevelPriority; exports.LoggerlessTransport = LoggerlessTransport; exports.testTransportOutput = testTransportOutput; //# sourceMappingURL=index.cjs.map