Class WindowsNTEventLog

java.lang.Object
windowsnt.eventlog.WindowsNTEventLog

public class WindowsNTEventLog extends Object
The Windows NT Event Log of iiziServer (CC-SERVER-RESTART-UPDATE-V5, stage F, from NetPhantom's class of the same name with its defects fixed): events of a registered source go through the JNI DLL 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
  • Field Details

    • EVENTCLASS_ERROR

      public static final int EVENTCLASS_ERROR
      The event class for errors (1).
      See Also:
    • EVENTCLASS_CRITICAL

      public static final int EVENTCLASS_CRITICAL
      The event class for critical events (2).
      See Also:
    • EVENTCLASS_WARNING

      public static final int EVENTCLASS_WARNING
      The event class for warnings (3).
      See Also:
    • EVENTCLASS_INFORMATIONAL

      public static final int EVENTCLASS_INFORMATIONAL
      The event class for informational events (4).
      See Also:
    • DEFAULT_SOURCE

      public static final String DEFAULT_SOURCE
      The default event source.
      See Also:
    • DLL_X64

      public static final String DLL_X64
      The DLL under the installation, by architecture.
      See Also:
    • DLL_ARM64

      public static final String DLL_ARM64
      The DLL under the installation, by architecture.
      See Also:
  • Constructor Details

    • WindowsNTEventLog

      public WindowsNTEventLog()
  • Method Details

    • isWindows

      public static boolean isWindows()
      Checks if this is Windows.
      Returns:
      true on Windows.
    • isARM64

      public static boolean isARM64(String osArch)
      Checks if this is an ARM64 JVM.
      Parameters:
      osArch - The os.arch property.
      Returns:
      true for arm64 and aarch64.
    • dllFile

      public static File dllFile(File install, String osArch)
      Names the DLL under an installation for an architecture: the absolute file System.load takes (NetPhantom's relative loadLibrary name was refused by the JDK).
      Parameters:
      install - The installation directory (the server's current directory).
      osArch - The os.arch property.
      Returns:
      The absolute file, which may not exist.
    • isSourceRegistered

      public static boolean isSourceRegistered(String name)
      Checks if an event source is registered: the key HKLM\SYSTEM\CurrentControlSet\Services\EventLog\Application\<source> exists, read with reg 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

      public static void enable(File dll, String sourceName)
      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 until enable(File, String) again.
    • isEnabled

      public static boolean isEnabled()
      Checks if the event log is enabled.
      Returns:
      true after enable(File, String).
    • getSource

      public static String getSource()
      Gets the event source in use.
      Returns:
      The source, null while disabled.
    • setSink

      public static void setSink(WindowsNTEventLog.Sink s)
      Sets the sink: a test's recorder, or null for the native one.
      Parameters:
      s - The sink, null for the DLL.
    • logEvent

      public static void logEvent(String msg)
      Logs an informational event under the source in use.
      Parameters:
      msg - The message.
    • logEvent

      public static void logEvent(int eventClass, String msg)
      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_WARNING or EVENTCLASS_INFORMATIONAL.
      msg - The message, cut at 4000 characters (the DLL cuts at 4095 UTF-16 units).