UNPKG

@logtape/windows-eventlog

Version:

Windows Event Log sink for LogTape

38 lines (37 loc) 1.35 kB
//#region src/formatter.ts /** * Formats a log record message into a string suitable for Windows Event Log. * Combines the template and arguments into a readable message. */ function formatMessage(record) { let message = ""; for (let i = 0; i < record.message.length; i++) if (i % 2 === 0) message += record.message[i]; else { const arg = record.message[i]; if (typeof arg === "string") message += arg; else message += JSON.stringify(arg); } return message; } /** * Formats additional context information for the log entry. * Includes category, properties, and other metadata. */ function formatContext(record) { const context = []; if (record.category && record.category.length > 0) context.push(`Category: ${record.category.join(".")}`); if (record.properties && Object.keys(record.properties).length > 0) context.push(`Properties: ${JSON.stringify(record.properties)}`); context.push(`Timestamp: ${new Date(record.timestamp).toISOString()}`); return context.length > 0 ? `\n\n${context.join("\n")}` : ""; } /** * Default way of rendering a record into text that goes in the event log. */ function defaultWindowsEventlogFormatter(record) { const msg = formatMessage(record); const ctx = formatContext(record); return msg + ctx; } //#endregion export { defaultWindowsEventlogFormatter }; //# sourceMappingURL=formatter.js.map