Class LogStream
java.lang.Object
de.craftsblock.craftsnet.logging.mutate.LogStream
A utility class for logging to files.
This class provides methods to log messages to files, handle error logs, and redirect standard output and error streams to log files.
- Since:
- 3.0.2-SNAPSHOT
- See Also:
-
MutatedPrintStream
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidAdds a line to the log file.longcreateErrorLog(CraftsNet craftsNet, Throwable throwable) Creates an error log file for the given throwable.longcreateErrorLog(CraftsNet craftsNet, Throwable throwable, String protocol, String path) Creates an error log file for the given exception.longCreates an error log file for the given throwable.Returns an unmodifiable list of all currently registeredLogStreamMutators.booleanChecks whether the givenLogStreamMutatoris already registered or not.voidregisterLogStreamMutator(LogStreamMutator mutator) Registers a newLogStreamMutatorthat will be applied to each line written to the log stream.voidskipNext()Skips the next input on theSystem.outstream, if it is a file log stream.voidskipNext(@org.jetbrains.annotations.Range(from=1L, to=2147483647L) int line) Skips the next n inputs on theSystem.outstream, if it is a file log stream.voidstart()Starts logging to files.voidstop()Stops the logging to filesvoidUnregisters a previously registeredLogStreamMutator.
-
Constructor Details
-
LogStream
Constructs a newLogStreaminstance with a specified maximum number of log files.- Parameters:
craftsNet- The instance ofCraftsNet, which is using this logging utils.logToFiles-trueif logging to files is enabled,falseotherwise.max- the maximum number of log files to retain. Once this limit is reached, older log files may be deleted or rotated out to maintain the limit.
-
-
Method Details
-
registerLogStreamMutator
Registers a newLogStreamMutatorthat will be applied to each line written to the log stream.- Parameters:
mutator- TheLogStreamMutatorto register.- Since:
- 3.5.0
-
unregisterLogStreamMutator
Unregisters a previously registeredLogStreamMutator.- Parameters:
mutator- TheLogStreamMutatorto remove.- Since:
- 3.5.0
-
isLogStreamMutatorRegistered
Checks whether the givenLogStreamMutatoris already registered or not.- Parameters:
mutator- TheLogStreamMutatorto check.- Returns:
trueif theLogStreamMutatoris registered,falseotherwise.
-
getLogStreamMutators
Returns an unmodifiable list of all currently registeredLogStreamMutators.- Returns:
- A list of registered log stream mutators.
- Since:
- 3.5.0
-
start
public void start()Starts logging to files. This method sets up file logging by redirecting standard output and error streams to log files. -
stop
public void stop()Stops the logging to files -
addLine
Adds a line to the log file. This method adds a line to the current log file.- Parameters:
line- The line to add to the log file.
-
createErrorLog
Creates an error log file for the given exception. This method creates an error log file containing the stack trace of the given exception.- Parameters:
craftsNet- The CraftsNet instance which instantiates thisthrowable- The throwable for which to create the error log file.protocol- The protocol associated with the error.path- The path associated with the error.- Returns:
- The identifier of the error log file.
-
createErrorLog
Creates an error log file for the given throwable. This method creates an error log file containing the stack trace of the given throwable.- Parameters:
craftsNet- The CraftsNet instance which instantiates thisthrowable- The throwable for which to create the error log file.- Returns:
- The identifier of the error log file.
-
createErrorLog
Creates an error log file for the given throwable. This method creates an error log file containing the stack trace of the given throwable, along with additional information.- Parameters:
craftsNet- The CraftsNet instance which instantiates this file logger.throwable- The throwable for which to create the error log file.additional- Additional information to include in the error log file.- Returns:
- The identifier of the error log file.
-
skipNext
public void skipNext()Skips the next input on theSystem.outstream, if it is a file log stream. -
skipNext
public void skipNext(@org.jetbrains.annotations.Range(from=1L, to=2147483647L) int line) Skips the next n inputs on theSystem.outstream, if it is a file log stream.- Parameters:
line- the amount of inputs to be skipped
-
getCraftsNet
- Returns:
- The instance of
CraftsNet.
-