@logtape/windows-eventlog 1.4.0-dev.428 → 1.4.0-dev.435

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,36 +1,8 @@
1
- const require_rolldown_runtime = require('./_virtual/rolldown_runtime.cjs');
2
- const require_types = require('./types.cjs');
3
- const require_platform = require('./platform.cjs');
1
+ const require_sink = require('./sink.cjs');
4
2
  const require_ffi_node = require('./ffi.node.cjs');
5
- const __logtape_logtape = require_rolldown_runtime.__toESM(require("@logtape/logtape"));
6
3
 
7
4
  //#region src/sink.node.ts
8
5
  /**
9
- * Formats a log record message into a string suitable for Windows Event Log.
10
- * Combines the template and arguments into a readable message.
11
- */
12
- function formatMessage(record) {
13
- let message = "";
14
- for (let i = 0; i < record.message.length; i++) if (i % 2 === 0) message += record.message[i];
15
- else {
16
- const arg = record.message[i];
17
- if (typeof arg === "string") message += arg;
18
- else message += JSON.stringify(arg);
19
- }
20
- return message;
21
- }
22
- /**
23
- * Formats additional context information for the log entry.
24
- * Includes category, properties, and other metadata.
25
- */
26
- function formatContext(record) {
27
- const context = [];
28
- if (record.category && record.category.length > 0) context.push(`Category: ${record.category.join(".")}`);
29
- if (record.properties && Object.keys(record.properties).length > 0) context.push(`Properties: ${JSON.stringify(record.properties)}`);
30
- context.push(`Timestamp: ${new Date(record.timestamp).toISOString()}`);
31
- return context.length > 0 ? `\n\n${context.join("\n")}` : "";
32
- }
33
- /**
34
6
  * Creates a Windows Event Log sink for Node.js environments using FFI.
35
7
  *
36
8
  * This implementation uses koffi to call Windows Event Log API directly,
@@ -53,58 +25,8 @@ function formatContext(record) {
53
25
  * @since 1.0.0
54
26
  */
55
27
  function getWindowsEventLogSink(options) {
56
- require_platform.validateWindowsPlatform();
57
- const { sourceName, eventIdMapping = {} } = options;
58
- const eventIds = {
59
- ...require_types.DEFAULT_EVENT_ID_MAPPING,
60
- ...eventIdMapping
61
- };
62
- let ffi = null;
63
- let initPromise = null;
64
- const metaLogger = (0, __logtape_logtape.getLogger)([
65
- "logtape",
66
- "meta",
67
- "windows-eventlog"
68
- ]);
69
- const sink = (record) => {
70
- const message = formatMessage(record);
71
- const context = formatContext(record);
72
- const fullMessage = message + context;
73
- const eventType = require_types.mapLogLevelToEventType(record.level);
74
- const eventId = eventIds[record.level];
75
- if (!ffi) {
76
- ffi = new require_ffi_node.WindowsEventLogFFI(sourceName);
77
- initPromise = ffi.initialize().then(() => {
78
- if (ffi) try {
79
- ffi.writeEvent(eventType, eventId, fullMessage);
80
- } catch (error) {
81
- metaLogger.error("Failed to write to Windows Event Log: {error}", { error });
82
- }
83
- }).catch((error) => {
84
- metaLogger.error("Failed to initialize Windows Event Log FFI: {error}", { error });
85
- ffi = null;
86
- initPromise = null;
87
- });
88
- } else if (initPromise) initPromise = initPromise.then(() => {
89
- if (ffi) try {
90
- ffi.writeEvent(eventType, eventId, fullMessage);
91
- } catch (error) {
92
- metaLogger.error("Failed to write to Windows Event Log: {error}", { error });
93
- }
94
- });
95
- else try {
96
- ffi.writeEvent(eventType, eventId, fullMessage);
97
- } catch (error) {
98
- metaLogger.error("Failed to write to Windows Event Log: {error}", { error });
99
- }
100
- };
101
- sink[Symbol.dispose] = () => {
102
- if (ffi) {
103
- ffi.dispose();
104
- ffi = null;
105
- }
106
- };
107
- return sink;
28
+ const ffi = new require_ffi_node.WindowsEventLogNodeFFI();
29
+ return require_sink.getWindowsEventLogSinkForFFI(ffi, options);
108
30
  }
109
31
 
110
32
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"sink.node.d.cts","names":[],"sources":["../src/sink.node.ts"],"sourcesContent":[],"mappings":";;;;;;;AAkFA;;;;;AAEoB;;;;;;;;;;;;;;;iBAFJ,sBAAA,UACL,6BACR,OAAO"}
1
+ {"version":3,"file":"sink.node.d.cts","names":[],"sources":["../src/sink.node.ts"],"sourcesContent":[],"mappings":";;;;;;;AA2BA;;;;;AAEoB;;;;;;;;;;;;;;;iBAFJ,sBAAA,UACL,6BACR,OAAO"}
@@ -1 +1 @@
1
- {"version":3,"file":"sink.node.d.ts","names":[],"sources":["../src/sink.node.ts"],"sourcesContent":[],"mappings":";;;;;;;AAkFA;;;;;AAEoB;;;;;;;;;;;;;;;iBAFJ,sBAAA,UACL,6BACR,OAAO"}
1
+ {"version":3,"file":"sink.node.d.ts","names":[],"sources":["../src/sink.node.ts"],"sourcesContent":[],"mappings":";;;;;;;AA2BA;;;;;AAEoB;;;;;;;;;;;;;;;iBAFJ,sBAAA,UACL,6BACR,OAAO"}
package/dist/sink.node.js CHANGED
@@ -1,35 +1,8 @@
1
- import { DEFAULT_EVENT_ID_MAPPING, mapLogLevelToEventType } from "./types.js";
2
- import { validateWindowsPlatform } from "./platform.js";
3
- import { WindowsEventLogFFI } from "./ffi.node.js";
4
- import { getLogger } from "@logtape/logtape";
1
+ import { getWindowsEventLogSinkForFFI } from "./sink.js";
2
+ import { WindowsEventLogNodeFFI } from "./ffi.node.js";
5
3
 
6
4
  //#region src/sink.node.ts
7
5
  /**
8
- * Formats a log record message into a string suitable for Windows Event Log.
9
- * Combines the template and arguments into a readable message.
10
- */
11
- function formatMessage(record) {
12
- let message = "";
13
- for (let i = 0; i < record.message.length; i++) if (i % 2 === 0) message += record.message[i];
14
- else {
15
- const arg = record.message[i];
16
- if (typeof arg === "string") message += arg;
17
- else message += JSON.stringify(arg);
18
- }
19
- return message;
20
- }
21
- /**
22
- * Formats additional context information for the log entry.
23
- * Includes category, properties, and other metadata.
24
- */
25
- function formatContext(record) {
26
- const context = [];
27
- if (record.category && record.category.length > 0) context.push(`Category: ${record.category.join(".")}`);
28
- if (record.properties && Object.keys(record.properties).length > 0) context.push(`Properties: ${JSON.stringify(record.properties)}`);
29
- context.push(`Timestamp: ${new Date(record.timestamp).toISOString()}`);
30
- return context.length > 0 ? `\n\n${context.join("\n")}` : "";
31
- }
32
- /**
33
6
  * Creates a Windows Event Log sink for Node.js environments using FFI.
34
7
  *
35
8
  * This implementation uses koffi to call Windows Event Log API directly,
@@ -52,58 +25,8 @@ function formatContext(record) {
52
25
  * @since 1.0.0
53
26
  */
54
27
  function getWindowsEventLogSink(options) {
55
- validateWindowsPlatform();
56
- const { sourceName, eventIdMapping = {} } = options;
57
- const eventIds = {
58
- ...DEFAULT_EVENT_ID_MAPPING,
59
- ...eventIdMapping
60
- };
61
- let ffi = null;
62
- let initPromise = null;
63
- const metaLogger = getLogger([
64
- "logtape",
65
- "meta",
66
- "windows-eventlog"
67
- ]);
68
- const sink = (record) => {
69
- const message = formatMessage(record);
70
- const context = formatContext(record);
71
- const fullMessage = message + context;
72
- const eventType = mapLogLevelToEventType(record.level);
73
- const eventId = eventIds[record.level];
74
- if (!ffi) {
75
- ffi = new WindowsEventLogFFI(sourceName);
76
- initPromise = ffi.initialize().then(() => {
77
- if (ffi) try {
78
- ffi.writeEvent(eventType, eventId, fullMessage);
79
- } catch (error) {
80
- metaLogger.error("Failed to write to Windows Event Log: {error}", { error });
81
- }
82
- }).catch((error) => {
83
- metaLogger.error("Failed to initialize Windows Event Log FFI: {error}", { error });
84
- ffi = null;
85
- initPromise = null;
86
- });
87
- } else if (initPromise) initPromise = initPromise.then(() => {
88
- if (ffi) try {
89
- ffi.writeEvent(eventType, eventId, fullMessage);
90
- } catch (error) {
91
- metaLogger.error("Failed to write to Windows Event Log: {error}", { error });
92
- }
93
- });
94
- else try {
95
- ffi.writeEvent(eventType, eventId, fullMessage);
96
- } catch (error) {
97
- metaLogger.error("Failed to write to Windows Event Log: {error}", { error });
98
- }
99
- };
100
- sink[Symbol.dispose] = () => {
101
- if (ffi) {
102
- ffi.dispose();
103
- ffi = null;
104
- }
105
- };
106
- return sink;
28
+ const ffi = new WindowsEventLogNodeFFI();
29
+ return getWindowsEventLogSinkForFFI(ffi, options);
107
30
  }
108
31
 
109
32
  //#endregion
@@ -1 +1 @@
1
- {"version":3,"file":"sink.node.js","names":["record: LogRecord","context: string[]","options: WindowsEventLogSinkOptions","ffi: WindowsEventLogFFI | null","initPromise: Promise<void> | null","sink: Sink & Disposable"],"sources":["../src/sink.node.ts"],"sourcesContent":["import type { LogRecord, Sink } from \"@logtape/logtape\";\nimport { getLogger } from \"@logtape/logtape\";\nimport type { WindowsEventLogSinkOptions } from \"./types.ts\";\nimport {\n DEFAULT_EVENT_ID_MAPPING,\n mapLogLevelToEventType,\n type WindowsEventLogError as _WindowsEventLogError,\n} from \"./types.ts\";\nimport { validateWindowsPlatform } from \"./platform.ts\";\nimport { WindowsEventLogFFI } from \"./ffi.node.ts\";\n\n/**\n * Formats a log record message into a string suitable for Windows Event Log.\n * Combines the template and arguments into a readable message.\n */\nfunction formatMessage(record: LogRecord): string {\n let message = \"\";\n\n // Combine template parts with arguments\n for (let i = 0; i < record.message.length; i++) {\n if (i % 2 === 0) {\n // Template part\n message += record.message[i];\n } else {\n // Argument - serialize it\n const arg = record.message[i];\n if (typeof arg === \"string\") {\n message += arg;\n } else {\n message += JSON.stringify(arg);\n }\n }\n }\n\n return message;\n}\n\n/**\n * Formats additional context information for the log entry.\n * Includes category, properties, and other metadata.\n */\nfunction formatContext(record: LogRecord): string {\n const context: string[] = [];\n\n // Add category if present\n if (record.category && record.category.length > 0) {\n context.push(`Category: ${record.category.join(\".\")}`);\n }\n\n // Add properties if present\n if (record.properties && Object.keys(record.properties).length > 0) {\n context.push(`Properties: ${JSON.stringify(record.properties)}`);\n }\n\n // Add timestamp\n context.push(`Timestamp: ${new Date(record.timestamp).toISOString()}`);\n\n return context.length > 0 ? `\\n\\n${context.join(\"\\n\")}` : \"\";\n}\n\n/**\n * Creates a Windows Event Log sink for Node.js environments using FFI.\n *\n * This implementation uses koffi to call Windows Event Log API directly,\n * providing high performance logging without external dependencies.\n *\n * @param options Configuration options for the sink\n * @returns A LogTape sink that writes to Windows Event Log\n * @throws {WindowsPlatformError} If not running on Windows\n * @throws {WindowsEventLogError} If Event Log operations fail\n *\n * @example\n * ```typescript\n * import { getWindowsEventLogSink } from \"@logtape/windows-eventlog\";\n *\n * const sink = getWindowsEventLogSink({\n * sourceName: \"MyApp\"\n * });\n * ```\n *\n * @since 1.0.0\n */\nexport function getWindowsEventLogSink(\n options: WindowsEventLogSinkOptions,\n): Sink & Disposable {\n // Validate platform early\n validateWindowsPlatform();\n\n const {\n sourceName,\n eventIdMapping = {},\n } = options;\n\n // Merge with default event ID mapping\n const eventIds = { ...DEFAULT_EVENT_ID_MAPPING, ...eventIdMapping };\n\n let ffi: WindowsEventLogFFI | null = null;\n let initPromise: Promise<void> | null = null;\n const metaLogger = getLogger([\"logtape\", \"meta\", \"windows-eventlog\"]);\n\n const sink: Sink & Disposable = (record: LogRecord) => {\n // Format the complete message\n const message = formatMessage(record);\n const context = formatContext(record);\n const fullMessage = message + context;\n\n // Get event type and ID for this log level\n const eventType = mapLogLevelToEventType(record.level);\n const eventId = eventIds[record.level];\n\n // Initialize FFI on first use\n if (!ffi) {\n ffi = new WindowsEventLogFFI(sourceName);\n initPromise = ffi.initialize()\n .then(() => {\n // Write the first event after initialization\n if (ffi) {\n try {\n ffi.writeEvent(eventType, eventId, fullMessage);\n } catch (error) {\n metaLogger.error(\n \"Failed to write to Windows Event Log: {error}\",\n { error },\n );\n }\n }\n })\n .catch((error) => {\n metaLogger.error(\n \"Failed to initialize Windows Event Log FFI: {error}\",\n { error },\n );\n ffi = null; // Reset FFI on error\n initPromise = null;\n });\n } else if (initPromise) {\n // Still initializing - queue the write operation\n initPromise = initPromise.then(() => {\n if (ffi) {\n try {\n ffi.writeEvent(eventType, eventId, fullMessage);\n } catch (error) {\n metaLogger.error(\n \"Failed to write to Windows Event Log: {error}\",\n { error },\n );\n }\n }\n });\n } else {\n // Already initialized\n try {\n ffi.writeEvent(eventType, eventId, fullMessage);\n } catch (error) {\n metaLogger.error(\n \"Failed to write to Windows Event Log: {error}\",\n { error },\n );\n }\n }\n };\n\n // Implement Disposable for cleanup\n sink[Symbol.dispose] = () => {\n if (ffi) {\n ffi.dispose();\n ffi = null;\n }\n };\n\n return sink;\n}\n"],"mappings":";;;;;;;;;;AAeA,SAAS,cAAcA,QAA2B;CAChD,IAAI,UAAU;AAGd,MAAK,IAAI,IAAI,GAAG,IAAI,OAAO,QAAQ,QAAQ,IACzC,KAAI,IAAI,MAAM,EAEZ,YAAW,OAAO,QAAQ;MACrB;EAEL,MAAM,MAAM,OAAO,QAAQ;AAC3B,aAAW,QAAQ,SACjB,YAAW;MAEX,YAAW,KAAK,UAAU,IAAI;CAEjC;AAGH,QAAO;AACR;;;;;AAMD,SAAS,cAAcA,QAA2B;CAChD,MAAMC,UAAoB,CAAE;AAG5B,KAAI,OAAO,YAAY,OAAO,SAAS,SAAS,EAC9C,SAAQ,MAAM,YAAY,OAAO,SAAS,KAAK,IAAI,CAAC,EAAE;AAIxD,KAAI,OAAO,cAAc,OAAO,KAAK,OAAO,WAAW,CAAC,SAAS,EAC/D,SAAQ,MAAM,cAAc,KAAK,UAAU,OAAO,WAAW,CAAC,EAAE;AAIlE,SAAQ,MAAM,aAAa,IAAI,KAAK,OAAO,WAAW,aAAa,CAAC,EAAE;AAEtE,QAAO,QAAQ,SAAS,KAAK,MAAM,QAAQ,KAAK,KAAK,CAAC,IAAI;AAC3D;;;;;;;;;;;;;;;;;;;;;;;AAwBD,SAAgB,uBACdC,SACmB;AAEnB,0BAAyB;CAEzB,MAAM,EACJ,YACA,iBAAiB,CAAE,GACpB,GAAG;CAGJ,MAAM,WAAW;EAAE,GAAG;EAA0B,GAAG;CAAgB;CAEnE,IAAIC,MAAiC;CACrC,IAAIC,cAAoC;CACxC,MAAM,aAAa,UAAU;EAAC;EAAW;EAAQ;CAAmB,EAAC;CAErE,MAAMC,OAA0B,CAACL,WAAsB;EAErD,MAAM,UAAU,cAAc,OAAO;EACrC,MAAM,UAAU,cAAc,OAAO;EACrC,MAAM,cAAc,UAAU;EAG9B,MAAM,YAAY,uBAAuB,OAAO,MAAM;EACtD,MAAM,UAAU,SAAS,OAAO;AAGhC,OAAK,KAAK;AACR,SAAM,IAAI,mBAAmB;AAC7B,iBAAc,IAAI,YAAY,CAC3B,KAAK,MAAM;AAEV,QAAI,IACF,KAAI;AACF,SAAI,WAAW,WAAW,SAAS,YAAY;IAChD,SAAQ,OAAO;AACd,gBAAW,MACT,iDACA,EAAE,MAAO,EACV;IACF;GAEJ,EAAC,CACD,MAAM,CAAC,UAAU;AAChB,eAAW,MACT,uDACA,EAAE,MAAO,EACV;AACD,UAAM;AACN,kBAAc;GACf,EAAC;EACL,WAAU,YAET,eAAc,YAAY,KAAK,MAAM;AACnC,OAAI,IACF,KAAI;AACF,QAAI,WAAW,WAAW,SAAS,YAAY;GAChD,SAAQ,OAAO;AACd,eAAW,MACT,iDACA,EAAE,MAAO,EACV;GACF;EAEJ,EAAC;MAGF,KAAI;AACF,OAAI,WAAW,WAAW,SAAS,YAAY;EAChD,SAAQ,OAAO;AACd,cAAW,MACT,iDACA,EAAE,MAAO,EACV;EACF;CAEJ;AAGD,MAAK,OAAO,WAAW,MAAM;AAC3B,MAAI,KAAK;AACP,OAAI,SAAS;AACb,SAAM;EACP;CACF;AAED,QAAO;AACR"}
1
+ {"version":3,"file":"sink.node.js","names":["options: WindowsEventLogSinkOptions"],"sources":["../src/sink.node.ts"],"sourcesContent":["import type { Sink } from \"@logtape/logtape\";\nimport { WindowsEventLogNodeFFI } from \"./ffi.node.ts\";\nimport { getWindowsEventLogSinkForFFI } from \"./sink.ts\";\nimport type { WindowsEventLogSinkOptions } from \"./types.ts\";\n\n/**\n * Creates a Windows Event Log sink for Node.js environments using FFI.\n *\n * This implementation uses koffi to call Windows Event Log API directly,\n * providing high performance logging without external dependencies.\n *\n * @param options Configuration options for the sink\n * @returns A LogTape sink that writes to Windows Event Log\n * @throws {WindowsPlatformError} If not running on Windows\n * @throws {WindowsEventLogError} If Event Log operations fail\n *\n * @example\n * ```typescript\n * import { getWindowsEventLogSink } from \"@logtape/windows-eventlog\";\n *\n * const sink = getWindowsEventLogSink({\n * sourceName: \"MyApp\"\n * });\n * ```\n *\n * @since 1.0.0\n */\nexport function getWindowsEventLogSink(\n options: WindowsEventLogSinkOptions,\n): Sink & Disposable {\n const ffi = new WindowsEventLogNodeFFI();\n return getWindowsEventLogSinkForFFI(ffi, options);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AA2BA,SAAgB,uBACdA,SACmB;CACnB,MAAM,MAAM,IAAI;AAChB,QAAO,6BAA6B,KAAK,QAAQ;AAClD"}
package/dist/types.cjs CHANGED
@@ -1,16 +1,24 @@
1
1
 
2
2
  //#region src/types.ts
3
3
  /**
4
- * Default Event ID mapping for LogTape levels.
4
+ * Generic event message defined in netmsg.dll which consists only of
5
+ * placeholders and no extra text. This value is defined in LMErrlog.h
6
+ */
7
+ const NELOG_OEM_Code = 3299;
8
+ /**
9
+ * Default Event ID mapping for LogTape levels. The event ID is used to look up
10
+ * a string resource in a configured dynamic link library, which is then used
11
+ * as a formatting string, passing the log text as parameters. The default is
12
+ * to use an event ID which only writes the text supplied into the log.
5
13
  * @since 1.0.0
6
14
  */
7
15
  const DEFAULT_EVENT_ID_MAPPING = {
8
- fatal: 1,
9
- error: 2,
10
- warning: 3,
11
- info: 4,
12
- debug: 5,
13
- trace: 6
16
+ fatal: NELOG_OEM_Code,
17
+ error: NELOG_OEM_Code,
18
+ warning: NELOG_OEM_Code,
19
+ info: NELOG_OEM_Code,
20
+ debug: NELOG_OEM_Code,
21
+ trace: NELOG_OEM_Code
14
22
  };
15
23
  /**
16
24
  * Maps LogTape log levels to Windows Event Log event types
@@ -50,6 +58,7 @@ var WindowsEventLogError = class extends Error {
50
58
 
51
59
  //#endregion
52
60
  exports.DEFAULT_EVENT_ID_MAPPING = DEFAULT_EVENT_ID_MAPPING;
61
+ exports.NELOG_OEM_Code = NELOG_OEM_Code;
53
62
  exports.WindowsEventLogError = WindowsEventLogError;
54
63
  exports.WindowsPlatformError = WindowsPlatformError;
55
64
  exports.mapLogLevelToEventType = mapLogLevelToEventType;
package/dist/types.d.cts CHANGED
@@ -1,4 +1,4 @@
1
- import { LogLevel } from "@logtape/logtape";
1
+ import { LogLevel, TextFormatter } from "@logtape/logtape";
2
2
 
3
3
  //#region src/types.d.ts
4
4
 
@@ -38,6 +38,11 @@ interface WindowsEventLogSinkOptions {
38
38
  * ```
39
39
  */
40
40
  readonly eventIdMapping?: Partial<Record<LogLevel, number>>;
41
+ /**
42
+ * The text formatter to use.
43
+ * Defaults to {@link defaultWindowsEventlogFormatter}.
44
+ */
45
+ formatter?: TextFormatter;
41
46
  }
42
47
  /**
43
48
  * Windows Event Log entry types mapped to LogTape levels.
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.cts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";;;;;;AAMA;;AAiC2C,UAjC1B,0BAAA,CAiC0B;EAAQ;;AAAhB;AAyDnC;AAeA;;EAAkC,SACK,UAAA,EAAA,MAAA;EAAK;AADG;;;;;;;;;;;;;;;;;;;;;;4BAxEnB,QAAQ,OAAO;;;;;;;;;;;;cAyD9B,oBAAA,SAA6B,KAAK;;;;;;;cAelC,oBAAA,SAA6B,KAAA;uCACH"}
1
+ {"version":3,"file":"types.d.cts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";;;;;;AAMA;;AAiC2C,UAjC1B,0BAAA,CAiC0B;EAAQ;;;AAMxB;AAkE3B;AAeA;EAAkC,SAAA,UAAA,EAAA,MAAA;EAAA;;AAAa;;;;;;;;;;;;;;;;;;;;;4BAvFnB,QAAQ,OAAO;;;;;cAM7B;;;;;;;;;;;;cAkED,oBAAA,SAA6B,KAAK;;;;;;;cAelC,oBAAA,SAA6B,KAAA;uCACH"}
package/dist/types.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import { LogLevel } from "@logtape/logtape";
1
+ import { LogLevel, TextFormatter } from "@logtape/logtape";
2
2
 
3
3
  //#region src/types.d.ts
4
4
 
@@ -38,6 +38,11 @@ interface WindowsEventLogSinkOptions {
38
38
  * ```
39
39
  */
40
40
  readonly eventIdMapping?: Partial<Record<LogLevel, number>>;
41
+ /**
42
+ * The text formatter to use.
43
+ * Defaults to {@link defaultWindowsEventlogFormatter}.
44
+ */
45
+ formatter?: TextFormatter;
41
46
  }
42
47
  /**
43
48
  * Windows Event Log entry types mapped to LogTape levels.
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";;;;;;AAMA;;AAiC2C,UAjC1B,0BAAA,CAiC0B;EAAQ;;AAAhB;AAyDnC;AAeA;;EAAkC,SACK,UAAA,EAAA,MAAA;EAAK;AADG;;;;;;;;;;;;;;;;;;;;;;4BAxEnB,QAAQ,OAAO;;;;;;;;;;;;cAyD9B,oBAAA,SAA6B,KAAK;;;;;;;cAelC,oBAAA,SAA6B,KAAA;uCACH"}
1
+ {"version":3,"file":"types.d.ts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";;;;;;AAMA;;AAiC2C,UAjC1B,0BAAA,CAiC0B;EAAQ;;;AAMxB;AAkE3B;AAeA;EAAkC,SAAA,UAAA,EAAA,MAAA;EAAA;;AAAa;;;;;;;;;;;;;;;;;;;;;4BAvFnB,QAAQ,OAAO;;;;;cAM7B;;;;;;;;;;;;cAkED,oBAAA,SAA6B,KAAK;;;;;;;cAelC,oBAAA,SAA6B,KAAA;uCACH"}
package/dist/types.js CHANGED
@@ -1,15 +1,23 @@
1
1
  //#region src/types.ts
2
2
  /**
3
- * Default Event ID mapping for LogTape levels.
3
+ * Generic event message defined in netmsg.dll which consists only of
4
+ * placeholders and no extra text. This value is defined in LMErrlog.h
5
+ */
6
+ const NELOG_OEM_Code = 3299;
7
+ /**
8
+ * Default Event ID mapping for LogTape levels. The event ID is used to look up
9
+ * a string resource in a configured dynamic link library, which is then used
10
+ * as a formatting string, passing the log text as parameters. The default is
11
+ * to use an event ID which only writes the text supplied into the log.
4
12
  * @since 1.0.0
5
13
  */
6
14
  const DEFAULT_EVENT_ID_MAPPING = {
7
- fatal: 1,
8
- error: 2,
9
- warning: 3,
10
- info: 4,
11
- debug: 5,
12
- trace: 6
15
+ fatal: NELOG_OEM_Code,
16
+ error: NELOG_OEM_Code,
17
+ warning: NELOG_OEM_Code,
18
+ info: NELOG_OEM_Code,
19
+ debug: NELOG_OEM_Code,
20
+ trace: NELOG_OEM_Code
13
21
  };
14
22
  /**
15
23
  * Maps LogTape log levels to Windows Event Log event types
@@ -48,5 +56,5 @@ var WindowsEventLogError = class extends Error {
48
56
  };
49
57
 
50
58
  //#endregion
51
- export { DEFAULT_EVENT_ID_MAPPING, WindowsEventLogError, WindowsPlatformError, mapLogLevelToEventType };
59
+ export { DEFAULT_EVENT_ID_MAPPING, NELOG_OEM_Code, WindowsEventLogError, WindowsPlatformError, mapLogLevelToEventType };
52
60
  //# sourceMappingURL=types.js.map
package/dist/types.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"types.js","names":["DEFAULT_EVENT_ID_MAPPING: Record<LogLevel, number>","level: LogLevel","platform: string","message: string","cause?: Error"],"sources":["../src/types.ts"],"sourcesContent":["import type { LogLevel } from \"@logtape/logtape\";\n\n/**\n * Configuration options for the Windows Event Log sink.\n * @since 1.0.0\n */\nexport interface WindowsEventLogSinkOptions {\n /**\n * The name of the event source. This is typically your application name\n * and will appear as the \"Source\" in Windows Event Viewer.\n *\n * @example \"MyApplication\"\n */\n readonly sourceName: string;\n\n /**\n * The server name to write logs to. Use this for remote logging.\n *\n * @default undefined (local machine)\n */\n readonly serverName?: string;\n\n /**\n * Custom mapping of LogTape log levels to Windows Event IDs.\n * Event IDs are numeric identifiers that can be used for filtering\n * and automation in Windows Event Log.\n *\n * @default\n * ```typescript\n * {\n * fatal: 1,\n * error: 2,\n * warning: 3,\n * info: 4,\n * debug: 5,\n * trace: 6\n * }\n * ```\n */\n readonly eventIdMapping?: Partial<Record<LogLevel, number>>;\n}\n\n/**\n * Windows Event Log entry types mapped to LogTape levels.\n * These correspond to the event types visible in Windows Event Viewer.\n * @since 1.0.0\n */\nexport const WINDOWS_EVENT_TYPES: Record<LogLevel, number> = {\n fatal: 1, // Error\n error: 1, // Error\n warning: 2, // Warning\n info: 4, // Information\n debug: 4, // Information\n trace: 4, // Information\n} as const;\n\n/**\n * Default Event ID mapping for LogTape levels.\n * @since 1.0.0\n */\nexport const DEFAULT_EVENT_ID_MAPPING: Record<LogLevel, number> = {\n fatal: 1,\n error: 2,\n warning: 3,\n info: 4,\n debug: 5,\n trace: 6,\n} as const;\n\n/**\n * Windows Event Log event type constants\n */\nexport type EventType = 1 | 2 | 4; // Error, Warning, Information\n\n/**\n * Maps LogTape log levels to Windows Event Log event types\n */\nexport function mapLogLevelToEventType(level: LogLevel): EventType {\n switch (level) {\n case \"fatal\":\n case \"error\":\n return 1; // EVENTLOG_ERROR_TYPE\n case \"warning\":\n return 2; // EVENTLOG_WARNING_TYPE\n case \"info\":\n case \"debug\":\n case \"trace\":\n default:\n return 4; // EVENTLOG_INFORMATION_TYPE\n }\n}\n\n/**\n * Platform validation error thrown when trying to use the sink on non-Windows platforms.\n * @since 1.0.0\n */\nexport class WindowsPlatformError extends Error {\n constructor(platform: string) {\n super(\n `Windows Event Log sink can only be used on Windows platforms. ` +\n `Current platform: ${platform}. ` +\n `This package is designed specifically for Windows Event Log integration.`,\n );\n this.name = \"WindowsPlatformError\";\n }\n}\n\n/**\n * Error thrown when Windows Event Log operations fail.\n * @since 1.0.0\n */\nexport class WindowsEventLogError extends Error {\n constructor(message: string, cause?: Error) {\n super(`Windows Event Log error: ${message}`);\n this.name = \"WindowsEventLogError\";\n if (cause) {\n this.cause = cause;\n }\n }\n}\n"],"mappings":";;;;;AA4DA,MAAaA,2BAAqD;CAChE,OAAO;CACP,OAAO;CACP,SAAS;CACT,MAAM;CACN,OAAO;CACP,OAAO;AACR;;;;AAUD,SAAgB,uBAAuBC,OAA4B;AACjE,SAAQ,OAAR;EACE,KAAK;EACL,KAAK,QACH,QAAO;EACT,KAAK,UACH,QAAO;EACT,KAAK;EACL,KAAK;EACL,KAAK;EACL,QACE,QAAO;CACV;AACF;;;;;AAMD,IAAa,uBAAb,cAA0C,MAAM;CAC9C,YAAYC,UAAkB;AAC5B,SACG,kFACsB,SAAS,4EAEjC;AACD,OAAK,OAAO;CACb;AACF;;;;;AAMD,IAAa,uBAAb,cAA0C,MAAM;CAC9C,YAAYC,SAAiBC,OAAe;AAC1C,SAAO,2BAA2B,QAAQ,EAAE;AAC5C,OAAK,OAAO;AACZ,MAAI,MACF,MAAK,QAAQ;CAEhB;AACF"}
1
+ {"version":3,"file":"types.js","names":["DEFAULT_EVENT_ID_MAPPING: Record<LogLevel, number>","level: LogLevel","platform: string","message: string","cause?: Error"],"sources":["../src/types.ts"],"sourcesContent":["import type { LogLevel, TextFormatter } from \"@logtape/logtape\";\n\n/**\n * Configuration options for the Windows Event Log sink.\n * @since 1.0.0\n */\nexport interface WindowsEventLogSinkOptions {\n /**\n * The name of the event source. This is typically your application name\n * and will appear as the \"Source\" in Windows Event Viewer.\n *\n * @example \"MyApplication\"\n */\n readonly sourceName: string;\n\n /**\n * The server name to write logs to. Use this for remote logging.\n *\n * @default undefined (local machine)\n */\n readonly serverName?: string;\n\n /**\n * Custom mapping of LogTape log levels to Windows Event IDs.\n * Event IDs are numeric identifiers that can be used for filtering\n * and automation in Windows Event Log.\n *\n * @default\n * ```typescript\n * {\n * fatal: 1,\n * error: 2,\n * warning: 3,\n * info: 4,\n * debug: 5,\n * trace: 6\n * }\n * ```\n */\n readonly eventIdMapping?: Partial<Record<LogLevel, number>>;\n\n /**\n * The text formatter to use.\n * Defaults to {@link defaultWindowsEventlogFormatter}.\n */\n formatter?: TextFormatter;\n}\n\n/**\n * Windows Event Log entry types mapped to LogTape levels.\n * These correspond to the event types visible in Windows Event Viewer.\n * @since 1.0.0\n */\nexport const WINDOWS_EVENT_TYPES: Record<LogLevel, number> = {\n fatal: 1, // Error\n error: 1, // Error\n warning: 2, // Warning\n info: 4, // Information\n debug: 4, // Information\n trace: 4, // Information\n} as const;\n\n/**\n * Generic event message defined in netmsg.dll which consists only of\n * placeholders and no extra text. This value is defined in LMErrlog.h\n */\nexport const NELOG_OEM_Code = 3299;\n\n/**\n * Default Event ID mapping for LogTape levels. The event ID is used to look up\n * a string resource in a configured dynamic link library, which is then used\n * as a formatting string, passing the log text as parameters. The default is\n * to use an event ID which only writes the text supplied into the log.\n * @since 1.0.0\n */\nexport const DEFAULT_EVENT_ID_MAPPING: Record<LogLevel, number> = {\n fatal: NELOG_OEM_Code,\n error: NELOG_OEM_Code,\n warning: NELOG_OEM_Code,\n info: NELOG_OEM_Code,\n debug: NELOG_OEM_Code,\n trace: NELOG_OEM_Code,\n} as const;\n\n/**\n * Windows Event Log event type constants\n */\nexport type EventType = 1 | 2 | 4; // Error, Warning, Information\n\n/**\n * Maps LogTape log levels to Windows Event Log event types\n */\nexport function mapLogLevelToEventType(level: LogLevel): EventType {\n switch (level) {\n case \"fatal\":\n case \"error\":\n return 1; // EVENTLOG_ERROR_TYPE\n case \"warning\":\n return 2; // EVENTLOG_WARNING_TYPE\n case \"info\":\n case \"debug\":\n case \"trace\":\n default:\n return 4; // EVENTLOG_INFORMATION_TYPE\n }\n}\n\n/**\n * Platform validation error thrown when trying to use the sink on non-Windows platforms.\n * @since 1.0.0\n */\nexport class WindowsPlatformError extends Error {\n constructor(platform: string) {\n super(\n `Windows Event Log sink can only be used on Windows platforms. ` +\n `Current platform: ${platform}. ` +\n `This package is designed specifically for Windows Event Log integration.`,\n );\n this.name = \"WindowsPlatformError\";\n }\n}\n\n/**\n * Error thrown when Windows Event Log operations fail.\n * @since 1.0.0\n */\nexport class WindowsEventLogError extends Error {\n constructor(message: string, cause?: Error) {\n super(`Windows Event Log error: ${message}`);\n this.name = \"WindowsEventLogError\";\n if (cause) {\n this.cause = cause;\n }\n }\n}\n"],"mappings":";;;;;AAkEA,MAAa,iBAAiB;;;;;;;;AAS9B,MAAaA,2BAAqD;CAChE,OAAO;CACP,OAAO;CACP,SAAS;CACT,MAAM;CACN,OAAO;CACP,OAAO;AACR;;;;AAUD,SAAgB,uBAAuBC,OAA4B;AACjE,SAAQ,OAAR;EACE,KAAK;EACL,KAAK,QACH,QAAO;EACT,KAAK,UACH,QAAO;EACT,KAAK;EACL,KAAK;EACL,KAAK;EACL,QACE,QAAO;CACV;AACF;;;;;AAMD,IAAa,uBAAb,cAA0C,MAAM;CAC9C,YAAYC,UAAkB;AAC5B,SACG,kFACsB,SAAS,4EAEjC;AACD,OAAK,OAAO;CACb;AACF;;;;;AAMD,IAAa,uBAAb,cAA0C,MAAM;CAC9C,YAAYC,SAAiBC,OAAe;AAC1C,SAAO,2BAA2B,QAAQ,EAAE;AAC5C,OAAK,OAAO;AACZ,MAAI,MACF,MAAK,QAAQ;CAEhB;AACF"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@logtape/windows-eventlog",
3
- "version": "1.4.0-dev.428+7fcb0292",
3
+ "version": "1.4.0-dev.435+c427e434",
4
4
  "description": "Windows Event Log sink for LogTape",
5
5
  "license": "MIT",
6
6
  "keywords": [
@@ -57,7 +57,7 @@
57
57
  "dist/"
58
58
  ],
59
59
  "peerDependencies": {
60
- "@logtape/logtape": "^1.4.0-dev.428+7fcb0292"
60
+ "@logtape/logtape": "^1.4.0-dev.435+c427e434"
61
61
  },
62
62
  "dependencies": {
63
63
  "koffi": "^2.10.0"