@logtape/windows-eventlog 1.4.0-dev.426 → 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.
- package/README.md +28 -0
- package/dist/ffi.bun.cjs +13 -13
- package/dist/ffi.bun.js +13 -13
- package/dist/ffi.bun.js.map +1 -1
- package/dist/ffi.deno.cjs +21 -20
- package/dist/ffi.deno.js +21 -17
- package/dist/ffi.deno.js.map +1 -1
- package/dist/ffi.node.cjs +10 -15
- package/dist/ffi.node.js +10 -15
- package/dist/ffi.node.js.map +1 -1
- package/dist/formatter.cjs +38 -0
- package/dist/formatter.js +38 -0
- package/dist/formatter.js.map +1 -0
- package/dist/sink.bun.cjs +3 -70
- package/dist/sink.bun.d.cts.map +1 -1
- package/dist/sink.bun.d.ts.map +1 -1
- package/dist/sink.bun.js +4 -70
- package/dist/sink.bun.js.map +1 -1
- package/dist/sink.cjs +84 -0
- package/dist/sink.deno.cjs +3 -84
- package/dist/sink.deno.d.cts.map +1 -1
- package/dist/sink.deno.d.ts.map +1 -1
- package/dist/sink.deno.js +4 -84
- package/dist/sink.deno.js.map +1 -1
- package/dist/sink.js +84 -0
- package/dist/sink.js.map +1 -0
- package/dist/sink.node.cjs +3 -81
- package/dist/sink.node.d.cts.map +1 -1
- package/dist/sink.node.d.ts.map +1 -1
- package/dist/sink.node.js +4 -81
- package/dist/sink.node.js.map +1 -1
- package/dist/types.cjs +16 -7
- package/dist/types.d.cts +6 -1
- package/dist/types.d.cts.map +1 -1
- package/dist/types.d.ts +6 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/types.js +16 -8
- package/dist/types.js.map +1 -1
- package/package.json +2 -2
package/dist/sink.node.cjs
CHANGED
|
@@ -1,36 +1,8 @@
|
|
|
1
|
-
const
|
|
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
|
-
|
|
57
|
-
|
|
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
|
package/dist/sink.node.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sink.node.d.cts","names":[],"sources":["../src/sink.node.ts"],"sourcesContent":[],"mappings":";;;;;;;
|
|
1
|
+
{"version":3,"file":"sink.node.d.cts","names":[],"sources":["../src/sink.node.ts"],"sourcesContent":[],"mappings":";;;;;;;AA2BA;;;;;AAEoB;;;;;;;;;;;;;;;iBAFJ,sBAAA,UACL,6BACR,OAAO"}
|
package/dist/sink.node.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sink.node.d.ts","names":[],"sources":["../src/sink.node.ts"],"sourcesContent":[],"mappings":";;;;;;;
|
|
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 {
|
|
2
|
-
import {
|
|
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
|
-
|
|
56
|
-
|
|
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
|
package/dist/sink.node.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"sink.node.js","names":["
|
|
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
|
-
*
|
|
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:
|
|
9
|
-
error:
|
|
10
|
-
warning:
|
|
11
|
-
info:
|
|
12
|
-
debug:
|
|
13
|
-
trace:
|
|
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.
|
package/dist/types.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.cts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";;;;;;AAMA;;AAiC2C,UAjC1B,0BAAA,CAiC0B;EAAQ
|
|
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.
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","names":[],"sources":["../src/types.ts"],"sourcesContent":[],"mappings":";;;;;;AAMA;;AAiC2C,UAjC1B,0BAAA,CAiC0B;EAAQ
|
|
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
|
-
*
|
|
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:
|
|
8
|
-
error:
|
|
9
|
-
warning:
|
|
10
|
-
info:
|
|
11
|
-
debug:
|
|
12
|
-
trace:
|
|
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
|
+
{"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.
|
|
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.
|
|
60
|
+
"@logtape/logtape": "^1.4.0-dev.435+c427e434"
|
|
61
61
|
},
|
|
62
62
|
"dependencies": {
|
|
63
63
|
"koffi": "^2.10.0"
|