Class AuditLog

java.lang.Object
xyz.gmitch215.socketmc.log.AuditLog
Direct Known Subclasses:
ServerAuditLog

public abstract class AuditLog extends Object
Represents an audit log instance on either a server or a client.
  • Field Details

    • FILE_DATE_FORMAT

      public static final SimpleDateFormat FILE_DATE_FORMAT
      Represents the date format used to name the audit log files.
    • LOG_DATE_FORMAT

      public static final SimpleDateFormat LOG_DATE_FORMAT
      Represents the default date format used inside the audit log.
    • CLIENT_RECEIVED_MESSAGE

      public static final String CLIENT_RECEIVED_MESSAGE
      Represents the message format for when a client receives a packet.
      See Also:
    • folder

      protected final File folder
      The folder where the audit log is stored.
  • Constructor Details

    • AuditLog

      protected AuditLog(@NotNull @NotNull File folder)
      Constructs a new audit log instance. This will create the folder if it does not exist.
      Parameters:
      folder - The folder where the audit log is stored.
  • Method Details

    • getFolder

      @NotNull public @NotNull File getFolder()
      Gets the folder where the audit log is stored.
      Returns:
      The folder where the audit log is stored.
    • getCurrentFile

      @NotNull public @NotNull File getCurrentFile()
      Gets the current file where the audit log is stored. The file may not exist yet.
      Returns:
      Current Log File
    • clean

      public void clean()
      Deletes all .log files in the audit log folder.
    • log

      public void log(@NotNull @NotNull Level level, @NotNull @NotNull String message)
      Logs a message to the audit log.
      Parameters:
      level - Audit Log Level
      message - Message to log
    • log

      public void log(@NotNull @NotNull String message)
      Logs a message of level Level.INFO to the audit log.
      Parameters:
      message - Message to log
    • logSent

      public void logSent(@NotNull @NotNull Instruction sent, @NotNull @NotNull SocketPlugin sender)
      Logs a sent instruction to the audit log.
      Parameters:
      sent - The instruction that was sent.
      sender - The plugin that sent the instruction.
    • logReceived

      public void logReceived(@NotNull @NotNull Instruction received, @NotNull @NotNull SocketPlugin sender)
      Logs a received instruction to the audit log.
      Parameters:
      received - The instruction that was received.
      sender - The plugin that sent the instruction.
    • logSent

      public void logSent(@NotNull @NotNull RetrieverType<?> sent, @NotNull @NotNull SocketPlugin sender)
      Logs a sent retriever to the audit log.
      Parameters:
      sent - The retriever that was sent.
      sender - The plugin that sent the retriever.
    • logReceived

      public void logReceived(@NotNull @NotNull RetrieverType<?> received, @NotNull @NotNull SocketPlugin sender, @NotNull @NotNull Object value)
      Logs a received retriever to the audit log.
      Parameters:
      received - The retriever that was received.
      sender - The plugin that sent the retriever.
      value - The value of the retriever.
    • readLog

      @NotNull public @NotNull List<String> readLog()
      Reads the audit log and returns it as a string.
      Returns:
      The audit log as a string.
    • readLog

      @NotNull public @NotNull List<String> readLog(int lines)
      Reads the audit log and returns it as a string, limited to the specified number of lines.
      Parameters:
      lines - The number of lines to read, starting from the latest entry.
      Returns:
      The audit log as a string, limited to the specified number of lines.
    • readLog

      @NotNull public @NotNull List<String> readLog(int startLine, int endLine) throws IllegalArgumentException
      Reads the audit log and returns it as a string, limited to the specified range of lines.
      Parameters:
      startLine - The starting line to read.
      endLine - The ending line to read.
      Returns:
      The audit log as a string, limited to the specified range of lines.
      Throws:
      IllegalArgumentException - If startLine is greater than endLine.