Class LoggyFormatter

java.lang.Object
fr.diskmth.loggy.LoggyFormatter

public abstract class LoggyFormatter extends Object
An abstract class for formatting log messages using ANSI codes for color and style.
Since:
Loggy 1.0
  • Field Details

    • DEFAULT

      public static final LoggyFormatter DEFAULT
      The default LoggyFormatter with predefined ANSI codes for each log level.
  • Constructor Details

    • LoggyFormatter

      public LoggyFormatter()
  • Method Details

    • toJavaFormatter

      public static Formatter toJavaFormatter(LoggyFormatter formatter)
      Converts a LoggyFormatter to a Java Formatter.
      Parameters:
      formatter - the LoggyFormatter to convert
      Returns:
      a Java Formatter with the same formatting as the given LoggyFormatter
    • levelsFormat

      public abstract HashMap<LoggyLevel,List<ANSI>> levelsFormat()
      Returns the ANSI codes for each log level.
      Returns:
      a HashMap of LoggyLevel to a List of ANSI codes
    • format

      public abstract String format(LoggyLevel level, String loggy, String message)
      Formats a log message using ANSI codes.
      Parameters:
      level - the log level
      loggy - the logger name
      message - the log message
      Returns:
      the formatted log message as a String
    • getFileFormatter

      public LoggyFormatter getFileFormatter()
      Returns a LoggyFormatter that clears all ANSI codes from the parent LoggyFormatter's output.
      Returns:
      a LoggyFormatter that does not use ANSI codes