-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
81 lines (72 loc) · 2.12 KB
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
"use strict";
// Require Node.js Dependencies
const { EventEmitter, on } = require("events");
/** @type {Winelog} */
const winelog = require("node-gyp-build")(__dirname);
// CONSTANTS
const kFiles = Object.freeze({
Application: "Application",
Setup: "Setup",
System: "System",
Security: "Security",
DirectoryService: "DirectoryService",
DNSServer: "DNSServer",
FileReplicationService: "FileReplicationService",
DFSReplication: "DFS Replication",
HardwareEvents: "HardwareEvents",
InternetExplorer: "Internet Explorer",
MediaCenter: "Media Center",
KeyManagementService: "Key Management Service",
ODiag: "ODiag",
OSession: "OSession"
});
const kLevels = Object.freeze({
SuccessAudit: 0,
FailureAudit: 1,
Error: 2,
Warning: 3,
Information: 4
});
/**
* @async
* @generator
* @function readEventLog
* @param {!string} name event log name
* @param {object} [options]
* @param {bool} [options.reverseDirection=true] switch between reverse and forward direction
* @param {string} [options.xPathQuery="*"] path to query
*
* @throws {TypeError}
* @throws {Error}
*
* @example
* for await (const event of readEventLog("Security")) {
* console.log(event);
* break;
* }
*/
async function* readEventLog(name, options = Object.create(null)) {
const { reverseDirection = true, xPathQuery = "*" } = options;
const localxPathQuery = String(xPathQuery);
if (Number.isNaN(localxPathQuery)) {
throw new TypeError("options.xPathQuery must be a valid string value");
}
const ee = new EventEmitter();
const closeReadWorker = winelog.readEventLog(String(name), localxPathQuery, Boolean(reverseDirection),
(error, row) => ee.emit("row", error, row));
try {
for await (const [error, row] of on(ee, "row")) {
if (error !== null) {
throw new Error(error);
}
if (row === null) {
break;
}
yield row;
}
}
finally {
closeReadWorker && closeReadWorker();
}
}
module.exports = { readEventLog, files: kFiles, levels: kLevels };