UNPKG

@logtape/windows-eventlog

Version:

Windows Event Log sink for LogTape

64 lines (62 loc) 1.94 kB
//#region src/types.ts /** * Generic event message defined in netmsg.dll which consists only of * placeholders and no extra text. This value is defined in LMErrlog.h */ const NELOG_OEM_Code = 3299; /** * Default Event ID mapping for LogTape levels. The event ID is used to look up * a string resource in a configured dynamic link library, which is then used * as a formatting string, passing the log text as parameters. The default is * to use an event ID which only writes the text supplied into the log. * @since 1.0.0 */ const DEFAULT_EVENT_ID_MAPPING = { fatal: NELOG_OEM_Code, error: NELOG_OEM_Code, warning: NELOG_OEM_Code, info: NELOG_OEM_Code, debug: NELOG_OEM_Code, trace: NELOG_OEM_Code }; /** * Maps LogTape log levels to Windows Event Log event types */ function mapLogLevelToEventType(level) { switch (level) { case "fatal": case "error": return 1; case "warning": return 2; case "info": case "debug": case "trace": default: return 4; } } /** * Platform validation error thrown when trying to use the sink on non-Windows platforms. * @since 1.0.0 */ var WindowsPlatformError = class extends Error { constructor(platform) { super(`Windows Event Log sink can only be used on Windows platforms. Current platform: ${platform}. This package is designed specifically for Windows Event Log integration.`); this.name = "WindowsPlatformError"; } }; /** * Error thrown when Windows Event Log operations fail. * @since 1.0.0 */ var WindowsEventLogError = class extends Error { constructor(message, cause) { super(`Windows Event Log error: ${message}`); this.name = "WindowsEventLogError"; if (cause) this.cause = cause; } }; //#endregion exports.DEFAULT_EVENT_ID_MAPPING = DEFAULT_EVENT_ID_MAPPING; exports.NELOG_OEM_Code = NELOG_OEM_Code; exports.WindowsEventLogError = WindowsEventLogError; exports.WindowsPlatformError = WindowsPlatformError; exports.mapLogLevelToEventType = mapLogLevelToEventType;