Class Logger

java.lang.Object
dev.prozilla.pine.common.logging.Logger
All Implemented Interfaces:
Lifecycle, LogHandler
Direct Known Subclasses:
AppLogger

public class Logger extends Object implements LogHandler, Lifecycle
Represents the main access points for logging. Manages different log levels, each with their own log handler, and formats logs.
  • Field Details

    • enabled

      protected boolean enabled
    • prefix

      protected String prefix
    • enableAnsi

      protected boolean enableAnsi
    • outputLogHandler

      protected LogHandler outputLogHandler
    • errorLogHandler

      protected LogHandler errorLogHandler
    • system

      public static final Logger system
      The global system logger for writing things to the console. Equivalent of System.out and System.err.
  • Constructor Details

    • Logger

      public Logger()
      Creates a logger without any log handlers.
    • Logger

      public Logger(LogHandler outputLogHandler)
      Creates a logger with an output log handler.
    • Logger

      public Logger(LogHandler outputLogHandler, LogHandler errorLogHandler)
      Creates a logger with an output and error log handler.
  • Method Details

    • log

      public void log()
      Description copied from interface: LogHandler
      Logs an empty line.
      Specified by:
      log in interface LogHandler
    • log

      public void log(boolean x)
      Specified by:
      log in interface LogHandler
    • log

      public void log(char x)
      Specified by:
      log in interface LogHandler
    • log

      public void log(int x)
      Specified by:
      log in interface LogHandler
    • log

      public void log(long x)
      Specified by:
      log in interface LogHandler
    • log

      public void log(float x)
      Specified by:
      log in interface LogHandler
    • log

      public void log(double x)
      Specified by:
      log in interface LogHandler
    • log

      public void log(char[] x)
      Specified by:
      log in interface LogHandler
    • log

      public void log(Object x)
      Specified by:
      log in interface LogHandler
    • logf

      public void logf(String format, Object... args)
      Description copied from interface: LogHandler
      Logs a formatted string of text.
      Specified by:
      logf in interface LogHandler
    • log

      public void log(String text)
      Description copied from interface: LogHandler
      Logs a string of text.
      Specified by:
      log in interface LogHandler
    • error

      public void error(String message, Throwable throwable)
      Logs an error message and a stack trace.
    • error

      public void error(String message)
      Logs an error message.
    • trace

      public void trace(Throwable throwable)
      Logs the stack trace of a throwable.
    • logPath

      public void logPath(String text, String filePath)
    • isOutputActive

      protected boolean isOutputActive()
    • isErrorActive

      protected boolean isErrorActive()
    • redirect

      public Logger redirect(LogLevel from, LogLevel to)
      Redirects logs from one log level to another.
      Parameters:
      from - Log level to redirect logs from
      to - Log level to redirect logs to
    • setEnabled

      public Logger setEnabled(boolean enabled)
      Enables or disables this logger.
      Parameters:
      enabled - If true, the logger will be enabled.
    • setPrefix

      public Logger setPrefix(String prefix)
      Sets the prefix of this logger.
      Parameters:
      prefix - Prefix to add to all logged strings.
    • enableAnsi

      public Logger enableAnsi()
    • disableAnsi

      public Logger disableAnsi()
    • formatPath

      public static String formatPath(String path)
    • formatBadge

      public static String formatBadge(String label)
    • formatBadge

      public static String formatBadge(String label, String color)