Class LogUtil

java.lang.Object
org.moera.lib.util.LogUtil

public class LogUtil extends Object
Utility class for formatting various data types into string representations. This class is designed to provide consistent formatting for logging purposes, ensuring proper representation and escaping of values.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    format(byte[] value)
    Formats a byte array into a human-readable string representation.
    static String
    format(Boolean value)
    Formats a Boolean value into its string representation.
    static String
    format(Integer value)
    Formats an Integer value into its string representation.
    static String
    format(Long value)
    Formats a Long value into its string representation.
    static String
    format(String value)
    Formats a given string value for logging purposes by escaping certain characters and surrounding the value in single quotes.
    static String
    format(String value, int maxLength)
    Formats a given string value for logging purposes by truncating it to a maximum length, escaping certain characters, and appending ellipsis if the truncation occurs.
    static String
    Formats a Timestamp value into its ISO 8601 string representation.
    static String
    format(UUID value)
    Formats a UUID value into its string representation enclosed in single quotes.
    static String
    format(Body value, int maxLength)
    Formats a Body object for logging purposes by encoding its content and truncating it to a specified maximum length.
    static String
    Formats a Long value representing a timestamp into its ISO 8601 string representation.

    Methods inherited from class java.lang.Object

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

    • LogUtil

      public LogUtil()
  • Method Details

    • format

      public static String format(String value)
      Formats a given string value for logging purposes by escaping certain characters and surrounding the value in single quotes. If the value is null, the string "null" is returned.
      Parameters:
      value - the string value to be formatted; may be null
      Returns:
      the formatted string, or "null" if the input is null
    • format

      public static String format(Integer value)
      Formats an Integer value into its string representation. If the value is null, the string "null" is returned.
      Parameters:
      value - the Integer value to be formatted; may be null
      Returns:
      the string representation of the integer, or "null" if the input is null
    • format

      public static String format(Long value)
      Formats a Long value into its string representation. If the value is null, the string "null" is returned.
      Parameters:
      value - the Long value to be formatted; may be null
      Returns:
      the string representation of the long value, or "null" if the input is null
    • format

      public static String format(Boolean value)
      Formats a Boolean value into its string representation. If the value is null, the string "null" is returned.
      Parameters:
      value - the Boolean value to be formatted; may be null
      Returns:
      the string representation of the boolean value, or "null" if the input is null
    • format

      public static String format(String value, int maxLength)
      Formats a given string value for logging purposes by truncating it to a maximum length, escaping certain characters, and appending ellipsis if the truncation occurs. If the value is null, the string "null" is returned.
      Parameters:
      value - the string value to be formatted; may be null
      maxLength - the maximum allowed length for the formatted string
      Returns:
      the formatted string
    • format

      public static String format(Body value, int maxLength)
      Formats a Body object for logging purposes by encoding its content and truncating it to a specified maximum length. If the Body is null, the string "null" is returned.
      Parameters:
      value - the Body object to be formatted; may be null
      maxLength - the maximum allowed length for the formatted string
      Returns:
      the formatted string, or "null" if the input is null
    • format

      public static String format(UUID value)
      Formats a UUID value into its string representation enclosed in single quotes. If the value is null, the string "null" is returned.
      Parameters:
      value - the UUID value to be formatted; may be null
      Returns:
      the formatted string, or "null" if the input is null
    • format

      public static String format(byte[] value)
      Formats a byte array into a human-readable string representation. If the byte array is null, the string "null" is returned. The formatting is handled by the Util.dumpShort(byte[]) method.
      Parameters:
      value - the byte array to format; may be null
      Returns:
      the formatted string representation of the byte array, or "null" if the input is null
    • format

      public static String format(Timestamp value)
      Formats a Timestamp value into its ISO 8601 string representation. If the value is null, the string "null" is returned.
      Parameters:
      value - the Timestamp value to be formatted; may be null
      Returns:
      the formatted string representation of the timestamp, or "null" if the input is null
    • formatTimestamp

      public static String formatTimestamp(Long value)
      Formats a Long value representing a timestamp into its ISO 8601 string representation. If the value is null, the string "null" is returned.
      Parameters:
      value - the Long value representing the timestamp to be formatted; may be null
      Returns:
      the formatted string representation of the timestamp, or "null" if the input is null