Class WindowsNTEventLog
WindowsNTEventLog64.dll, which is its own message file.What is fixed against NetPhantom's class. (1) The DLL is loaded with System.load and an absolute path (dllFile), by architecture: bin\ntservice\x64 or bin\ntservice\ARM64 under the installation; NetPhantom's loadLibrary("x64\\...") was refused by the JDK and the DLL never loaded. (2) logEvent calls WindowsNTEventLog64.logEvent0(String, int, String), the method the DLL exports; NetPhantom called its own, unexported one. (3) The log is enabled only once the event source is known to be REGISTERED (isSourceRegistered(String), read from the registry): the DLL calls ExitProcess(10) when it cannot register the source itself, which would end a server started by a non-administrator at its first event. is.bat INSTALL registers the source with reg add (D-13).
The sink is pluggable (setSink(WindowsNTEventLog.Sink)): the native one by default, a recorder in the tests. Nothing here depends on another IIZI class: the class is shared by the server and the tools jar.
- Author:
- Christopher Mindus
Nested Class Summary
Nested ClassesField Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe default event source.static final StringThe DLL under the installation, by architecture.static final StringThe DLL under the installation, by architecture.static final intThe event class for critical events (2).static final intThe event class for errors (1).static final intThe event class for informational events (4).static final intThe event class for warnings (3).Constructor Summary
ConstructorsMethod Summary
Modifier and TypeMethodDescriptionstatic voiddisable()Disables the event log:logEvent(String)does nothing untilenable(File, String)again.static FileNames the DLL under an installation for an architecture: the absolute fileSystem.loadtakes (NetPhantom's relativeloadLibraryname was refused by the JDK).static voidEnables the event log for a source whose registration the caller has checked (isSourceRegistered(String)), naming the DLL to load on the first event.static StringGets the event source in use.static booleanChecks if this is an ARM64 JVM.static booleanChecks if the event log is enabled.static booleanisSourceRegistered(String name) Checks if an event source is registered: the keyHKLM\SYSTEM\CurrentControlSet\Services\EventLog\Application\<source>exists, read withreg query(no JNA in the tools jar).static booleanChecks if this is Windows.static voidLogs an event under the source in use; nothing while disabled.static voidLogs an informational event under the source in use.static voidSets the sink: a test's recorder, or null for the native one.
Field Details
EVENTCLASS_ERROR
public static final int EVENTCLASS_ERRORThe event class for errors (1).- See Also:
EVENTCLASS_CRITICAL
public static final int EVENTCLASS_CRITICALThe event class for critical events (2).- See Also:
EVENTCLASS_WARNING
public static final int EVENTCLASS_WARNINGThe event class for warnings (3).- See Also:
EVENTCLASS_INFORMATIONAL
public static final int EVENTCLASS_INFORMATIONALThe event class for informational events (4).- See Also:
DEFAULT_SOURCE
DLL_X64
DLL_ARM64
Constructor Details
WindowsNTEventLog
public WindowsNTEventLog()
Method Details
isWindows
public static boolean isWindows()Checks if this is Windows.- Returns:
- true on Windows.
isARM64
Checks if this is an ARM64 JVM.- Parameters:
osArch- Theos.archproperty.- Returns:
- true for arm64 and aarch64.
dllFile
Names the DLL under an installation for an architecture: the absolute fileSystem.loadtakes (NetPhantom's relativeloadLibraryname was refused by the JDK).- Parameters:
install- The installation directory (the server's current directory).osArch- Theos.archproperty.- Returns:
- The absolute file, which may not exist.
isSourceRegistered
Checks if an event source is registered: the keyHKLM\SYSTEM\CurrentControlSet\Services\EventLog\Application\<source>exists, read withreg query(no JNA in the tools jar). The DLL would register it itself and exit the process with 10 when it cannot: the question is asked first instead.- Parameters:
name- The source name.- Returns:
- true when the key exists; false when it does not, on another OS, or when the registry cannot be asked.
enable
Enables the event log for a source whose registration the caller has checked (isSourceRegistered(String)), naming the DLL to load on the first event.- Parameters:
dll- The DLL file (dllFile).sourceName- The event source.- Throws:
IllegalArgumentException- If the DLL file does not exist or the source is blank.
disable
public static void disable()Disables the event log:logEvent(String)does nothing untilenable(File, String)again.isEnabled
public static boolean isEnabled()Checks if the event log is enabled.- Returns:
- true after
enable(File, String).
getSource
Gets the event source in use.- Returns:
- The source, null while disabled.
setSink
Sets the sink: a test's recorder, or null for the native one.- Parameters:
s- The sink, null for the DLL.
logEvent
Logs an informational event under the source in use.- Parameters:
msg- The message.
logEvent
Logs an event under the source in use; nothing while disabled. Never throws: a failing event log is not the server's problem.- Parameters:
eventClass-EVENTCLASS_ERROR,EVENTCLASS_CRITICAL,EVENTCLASS_WARNINGorEVENTCLASS_INFORMATIONAL.msg- The message, cut at 4000 characters (the DLL cuts at 4095 UTF-16 units).