java.lang.Object
com.github.eventmanager.EventManager

public class EventManager extends Object
The EventManager class is responsible for managing and logging events. It provides methods to log messages with different log levels and formats.
  • Field Details

  • Constructor Details

    • EventManager

      public EventManager(LogHandler logHandler)
      Constructs an EventManager with the specified LogHandler.
      Parameters:
      logHandler - the LogHandler to use for logging events.
    • EventManager

      public EventManager(String configPath)
      Constructs an EventManager with the specified configuration file path.
      Parameters:
      configPath - the path to the configuration file. Passing an empty string or invalid path will force the EventManager to fall back to the default configuration.
  • Method Details

    • stopEventThread

      public void stopEventThread()
      Stops the event thread by interrupting it and waiting for it to finish. This method should be called before shutting down the application to ensure that all events are written to the log file.
    • setCorrectOSSeperator

      public static String setCorrectOSSeperator(String path)
      Sets the correct OS-specific file separator in the given path.
      Parameters:
      path - the file path to adjust.
      Returns:
      the adjusted file path with the correct OS-specific separator.
    • writeEventToLogFile

      protected void writeEventToLogFile(String event)
      Writes the given event to the log file. If the event is not empty, it will be written to the log file specified in the configuration file. If the log file does not exist, it will be created. If the log file cannot be created or written to, an error message will be printed to the console.
      Parameters:
      event - the event to write to the log file.
    • logFatalMessage

      public void logFatalMessage(Object exception)
      Logs a fatal message.
      Parameters:
      exception - the exception to log.
    • logFatalMessage

      public void logFatalMessage(KeyValueWrapper... args)
      Logs a fatal message with key-value pairs.
      Parameters:
      args - the key-value pairs to log.
    • logFatalMessage

      public void logFatalMessage(EventCreator message)
      Logs a fatal message with a EventCreator message.
      Parameters:
      message - the message to log.
    • logErrorMessage

      public void logErrorMessage(Object exception)
      Logs an error message.
      Parameters:
      exception - the exception to log.
    • logErrorMessage

      public void logErrorMessage(KeyValueWrapper... args)
      Logs an error message with key-value pairs.
      Parameters:
      args - the key-value pairs to log.
    • logErrorMessage

      public void logErrorMessage(EventCreator message)
      Logs an error message with a EventCreator message.
      Parameters:
      message - the message to log.
    • logWarningMessage

      public void logWarningMessage(Object exception)
      Logs a warning message.
      Parameters:
      exception - the exception to log.
    • logWarningMessage

      public void logWarningMessage(KeyValueWrapper... args)
      Logs a warning message with key-value pairs.
      Parameters:
      args - the key-value pairs to log.
    • logWarningMessage

      public void logWarningMessage(EventCreator message)
      Logs a warning message with a EventCreator message.
      Parameters:
      message - the message to log.
    • areInfoLogsEnabled

      public boolean areInfoLogsEnabled()
      Checks if informational logs are enabled.
      Returns:
      true if informational logs are enabled, false otherwise.
    • logInfoMessage

      public void logInfoMessage(Object exception)
      Logs an informational message.
      Parameters:
      exception - the exception to log.
    • logInfoMessage

      public void logInfoMessage(KeyValueWrapper... args)
      Logs an informational message with key-value pairs.
      Parameters:
      args - the key-value pairs to log.
    • logInfoMessage

      public void logInfoMessage(EventCreator message)
      Logs an informational message with a EventCreator message.
      Parameters:
      message - the message to log.
    • logDebugMessage

      public void logDebugMessage(Object exception)
      Logs a debug message.
      Parameters:
      exception - the exception to log.
    • logDebugMessage

      public void logDebugMessage(KeyValueWrapper... args)
      Logs a debug message with key-value pairs.
      Parameters:
      args - the key-value pairs to log.
    • logDebugMessage

      public void logDebugMessage(EventCreator message)
      Logs a debug message with a EventCreator message.
      Parameters:
      message - the message to log.
    • initiateThreads

      protected void initiateThreads()
    • processEvent

      protected String processEvent(String event)
    • initiatEventThread

      @Deprecated public Thread initiatEventThread()
      Deprecated.
      This method is deprecated and will be removed in a future release, as it was not intended to be used by external classes... there was also a typo. Use ManagerBase.initiatEventThread() instead.
      Creates a new Thread to write events to the log file. It will run indefinitely until it is interrupted (either by calling the ManagerBase.stopEventThread() method or by the JVM shutting down). The thread will write events to the log file if the queue is not empty and internal events are enabled.
    • initiateEventThread

      protected Thread initiateEventThread()
    • setMetaDataFields

      protected Map<String,String> setMetaDataFields(String level)
      Sets the metadata fields for the event.
      Parameters:
      level - the log level of the event.
      Returns:
      a map containing the metadata fields.
    • logMessage

      protected void logMessage(String level, Object message)
      Logs a message to the destination file.
      Parameters:
      level - the log level of the message.
      message - the object to log.
    • writeEventToQueue

      protected void writeEventToQueue(String event)
      Writes the given event to the event queue. This method is thread-safe and can be called from multiple threads.
      Parameters:
      event - the event to write to the queue.
    • writeEventToProcessingQueue

      protected void writeEventToProcessingQueue(String event)