UNPKG

fixparser-plugin-log-console

Version:

Console / JSON logger for FIXParser

76 lines (74 loc) 2.36 kB
"use strict"; var __defProp = Object.defineProperty; var __getOwnPropDesc = Object.getOwnPropertyDescriptor; var __getOwnPropNames = Object.getOwnPropertyNames; var __hasOwnProp = Object.prototype.hasOwnProperty; var __export = (target, all) => { for (var name in all) __defProp(target, name, { get: all[name], enumerable: true }); }; var __copyProps = (to, from, except, desc) => { if (from && typeof from === "object" || typeof from === "function") { for (let key of __getOwnPropNames(from)) if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); } return to; }; var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); // src/ConsoleLogTransport.ts var ConsoleLogTransport_exports = {}; __export(ConsoleLogTransport_exports, { ConsoleLogTransport: () => ConsoleLogTransport }); module.exports = __toCommonJS(ConsoleLogTransport_exports); var ConsoleLogTransport = class { format; constructor({ format = "json" }) { this.format = format; } /** * Configures the format for console logging (either 'console' for text or 'json'). */ configure(config) { this.format = config.format || "json"; } /** * Sends the log message to the console in the configured format. */ async send(log) { if (this.format === "json") { console.log(JSON.stringify(log)); } else { const { name, id, message, level, ...additionalProperties } = log; const kv = Object.entries(additionalProperties).map(([key, value]) => `${key}: ${value}`); let logMessage = ""; if (name) { logMessage += `${name} `; } logMessage += `${id}: ${message}`; console.log(logMessage, kv.join(", ")); } } /** * Flushes the log buffer (if any buffering mechanism exists). */ async flush() { } /** * Closes the transport (not needed for console, but keeping the method for consistency). */ async close() { } /** * Returns the status of the transport (always "connected" for console). */ status() { return "connected"; } }; // Annotate the CommonJS export names for ESM import in node: 0 && (module.exports = { ConsoleLogTransport }); //# sourceMappingURL=ConsoleLogTransport.js.map