Class LogStream

java.lang.Object
de.craftsblock.craftsnet.logging.mutate.LogStream

public class LogStream extends Object
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 Details

    • LogStream

      public LogStream(CraftsNet craftsNet, boolean logToFiles, long max)
      Constructs a new LogStream instance with a specified maximum number of log files.
      Parameters:
      craftsNet - The instance of CraftsNet, which is using this logging utils.
      logToFiles - true if logging to files is enabled, false otherwise.
      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

      public void registerLogStreamMutator(LogStreamMutator mutator)
      Registers a new LogStreamMutator that will be applied to each line written to the log stream.
      Parameters:
      mutator - The LogStreamMutator to register.
      Since:
      3.5.0
    • unregisterLogStreamMutator

      public void unregisterLogStreamMutator(LogStreamMutator mutator)
      Unregisters a previously registered LogStreamMutator.
      Parameters:
      mutator - The LogStreamMutator to remove.
      Since:
      3.5.0
    • isLogStreamMutatorRegistered

      public boolean isLogStreamMutatorRegistered(LogStreamMutator mutator)
      Checks whether the given LogStreamMutator is already registered or not.
      Parameters:
      mutator - The LogStreamMutator to check.
      Returns:
      true if the LogStreamMutator is registered, false otherwise.
    • getLogStreamMutators

      public List<LogStreamMutator> getLogStreamMutators()
      Returns an unmodifiable list of all currently registered LogStreamMutators.
      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

      public void addLine(String line)
      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

      public long createErrorLog(CraftsNet craftsNet, Throwable throwable, String protocol, String path)
      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 this
      throwable - 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

      public long createErrorLog(CraftsNet craftsNet, Throwable throwable)
      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 this
      throwable - The throwable for which to create the error log file.
      Returns:
      The identifier of the error log file.
    • createErrorLog

      public long createErrorLog(CraftsNet craftsNet, Throwable throwable, Map<String,String> additional)
      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 the System.out stream, 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 the System.out stream, if it is a file log stream.
      Parameters:
      line - the amount of inputs to be skipped
    • getCraftsNet

      public CraftsNet getCraftsNet()
      The instance of CraftsNet which is owning the LogStream.
      Returns:
      The instance of CraftsNet.