Package xyz.gmitch215.socketmc.log
Class AuditLog
java.lang.Object
xyz.gmitch215.socketmc.log.AuditLog
- Direct Known Subclasses:
ServerAuditLog
Represents an audit log instance on either a server or a client.
-
Field Summary
Modifier and TypeFieldDescriptionstatic final String
Represents the message format for when a client receives a packet.static final SimpleDateFormat
Represents the date format used to name the audit log files.protected final File
The folder where the audit log is stored.static final SimpleDateFormat
Represents the default date format used inside the audit log. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
clean()
Deletes all.log
files in the audit log folder.Gets the current file where the audit log is stored.Gets the folder where the audit log is stored.void
Logs a message of levelLevel.INFO
to the audit log.void
Logs a message to the audit log.void
logReceived
(@NotNull Instruction received, @NotNull SocketPlugin sender) Logs a received instruction to the audit log.void
logReceived
(@NotNull RetrieverType<?> received, @NotNull SocketPlugin sender, @NotNull Object value) Logs a received retriever to the audit log.void
logSent
(@NotNull Instruction sent, @NotNull SocketPlugin sender) Logs a sent instruction to the audit log.void
logSent
(@NotNull RetrieverType<?> sent, @NotNull SocketPlugin sender) Logs a sent retriever to the audit log.readLog()
Reads the audit log and returns it as a string.readLog
(int lines) Reads the audit log and returns it as a string, limited to the specified number of lines.readLog
(int startLine, int endLine) Reads the audit log and returns it as a string, limited to the specified range of lines.
-
Field Details
-
FILE_DATE_FORMAT
Represents the date format used to name the audit log files. -
LOG_DATE_FORMAT
Represents the default date format used inside the audit log. -
CLIENT_RECEIVED_MESSAGE
Represents the message format for when a client receives a packet.- See Also:
-
folder
The folder where the audit log is stored.
-
-
Constructor Details
-
AuditLog
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
Gets the folder where the audit log is stored.- Returns:
- The folder where the audit log is stored.
-
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
Logs a message to the audit log.- Parameters:
level
- Audit Log Levelmessage
- Message to log
-
log
Logs a message of levelLevel.INFO
to the audit log.- Parameters:
message
- Message to log
-
logSent
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
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
Reads the audit log and returns it as a string.- Returns:
- The audit log as a string.
-
readLog
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
- IfstartLine
is greater thanendLine
.
-