java.lang.Object
com.github.eventmanager.formatters.EventCreator

public class EventCreator extends Object
The EventCreator class is a builder class that creates event logs. Contrary to the EventFormatter class, it can create event logs with a custom format. The format can be specified by the user when creating an instance of the EventCreator class. The format can be one of the following: "json", "xml", "csv", or "key-value".

The class includes information which can be found in the default format, such as the class name, method name, line number, timestamp, level, exception, message, and arguments. These values are generated when creating an instance of the EventCreator class, this should be kept in mind when creating events.
  • Constructor Details

    • EventCreator

      public EventCreator(String format)
      The constructor of the EventCreator class.
      Parameters:
      format - The format of the event log. The format can be one of the following: "json", "xml", "csv", or "key-value". If the format is not one of the specified formats, the default format is "key-value".
  • Method Details

    • lineNumber

      public EventCreator lineNumber()
      Appends the line number of the log to the event log.
      Returns:
      The EventCreator object.
    • timestamp

      public EventCreator timestamp(String timestampFormat)
      Appends the timestamp of the log to the event log.
      Parameters:
      timestampFormat - The format of the timestamp. If the format is not valid, the current timestamp is used. The format should be in the form of a pattern that can be used by the DateTimeFormatter
      Returns:
      The EventCreator object.
    • level

      public EventCreator level(String level)
      Appends the level of the log to the event log.
      Parameters:
      level - The level of the log.
      Returns:
      The EventCreator object.
    • className

      public EventCreator className()
      Appends the class name of the log to the event log.
      Returns:
      The EventCreator object.
    • methodName

      public EventCreator methodName()
      Appends the method name of the log to the event log.
      Returns:
      The EventCreator object.
    • exception

      public EventCreator exception(String exception)
      Appends the exception to the event.
      Parameters:
      exception - The exception of the log.
      Returns:
      The EventCreator object.
    • message

      public EventCreator message(String message)
      Appends the message of the log to the event log.
      Parameters:
      message - The message of the log.
      Returns:
      The EventCreator object.
    • args

      public EventCreator args(String args)
      Appends the arguments of the log to the event log.
      Parameters:
      args - The arguments of the log.
      Returns:
      The EventCreator object.
    • args

      public EventCreator args(String body, KeyValueWrapper args)
      Appends a key-value pairs o the log to the event log.
      Parameters:
      body - The body of the log.
      args - The key-value pair of the argument body.
      Returns:
      The EventCreator object.
    • args

      public EventCreator args(String body, KeyValueWrapper... args)
      Appends a number of key-value pairs of the log to the event log.
      Parameters:
      body - The body of the log.
      args - The key-value pair of the argument body.
      Returns:
      The EventCreator object.
    • create

      public String create()
      Finalizes the event log and returns it as a string.
      Returns:
      The event log as a string.