Package utility

Class Logging

java.lang.Object
utility.Logging

public final class Logging extends Object
Logging utility class for printing messages to the console with different severity levels.

This class provides methods to log messages with different severity levels (INFO, DONE, ERROR, WARNING) along with timestamps. It also includes a method to print software information and a set to manage warning keys to prevent excessive logging.

  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final Set<String>
    Set to keep track of logged warnings to avoid duplicate messages.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    Returns the current timestamp formatted as a string.
    static String
    Returns the current timestamp formatted as a string.
    static void
    Logs a message indicating completion with a timestamp.
    static void
    Logs an error message to the console with a timestamp.
    static void
    Logs an informational message to the console with a timestamp.
    static void
    Logs a warning message to the console with a timestamp.
    static void
    Logs a warning message to the console with a timestamp, but only once for each unique key.
    static void
    Prints the software information to the console.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • logDump

      public static final Set<String> logDump
      Set to keep track of logged warnings to avoid duplicate messages.
  • Constructor Details

    • Logging

      public Logging()
  • Method Details

    • printSoftwareInfo

      public static void printSoftwareInfo()
      Prints the software information to the console.

      This method displays the software name, version, and license in a formatted manner. The output is styled using ANSI escape codes for background and text color.

      Note: The software information is retrieved from the Musial class.

    • logInfo

      public static void logInfo(String msg)
      Logs an informational message to the console with a timestamp.

      This method formats the message with a timestamp and a "STATUS" label styled using ANSI escape codes. The formatted message is then printed to the console.

      Parameters:
      msg - The informational message to be logged.
    • logDone

      public static void logDone(String msg)
      Logs a message indicating completion with a timestamp.

      This method formats the message with a timestamp and a "DONE" label styled using ANSI escape codes. The formatted message is then printed to the console.

      Parameters:
      msg - The message indicating completion to be logged.
    • logError

      public static void logError(String msg)
      Logs an error message to the console with a timestamp.

      This method formats the message with a timestamp and an "ERROR" label styled using ANSI escape codes. The formatted message is then printed to the console.

      Parameters:
      msg - The error message to be logged.
    • logWarning

      public static void logWarning(String msg)
      Logs a warning message to the console with a timestamp.

      This method formats the message with a timestamp and a "WARNING" label styled using ANSI escape codes. The formatted message is then printed to the console.

      Parameters:
      msg - The warning message to be logged.
    • logWarningOnce

      public static void logWarningOnce(String key, String msg)
      Logs a warning message to the console with a timestamp, but only once for each unique key.

      This method checks if the warning message with the specified key has already been logged. If not, it logs the message and adds the key to the set of logged warnings.

      Parameters:
      key - The unique key for the warning message.
      msg - The warning message to be logged.
    • getTimestamp

      public static String getTimestamp()
      Returns the current timestamp formatted as a string.

      This method retrieves the current date and time, formats it using the specified date format, and returns it as a string.

      Returns:
      The current timestamp formatted as a string.
    • getDate

      public static String getDate()
      Returns the current timestamp formatted as a string.

      This method retrieves the current date, formats it using the specified date format, and returns it as a string.

      Returns:
      The current timestamp formatted as a string.