Class LoggingFormatter

java.lang.Object
java.util.logging.Formatter
com.google.cloud.hadoop.util.LoggingFormatter

public class LoggingFormatter extends Formatter
A custom logging formatter that prefixes log messages with an invocation ID. If the log message is in JSON format, the invocation ID is not prefixed.
  • Constructor Details

    • LoggingFormatter

      public LoggingFormatter(Formatter existingFormatter)
      Constructs a new LoggingFormatter that wraps an existing formatter.
      Parameters:
      existingFormatter - The formatter to be decorated.
  • Method Details

    • format

      public String format(LogRecord record)
      Formats the given log record by prefixing it with the invocation ID.
      Specified by:
      format in class Formatter
      Parameters:
      record - the log record to be formatted
      Returns:
      the formatted log message
    • addFormatter

      public static void addFormatter(Logger logger)
      Adds the custom logging formatter to all handlers of the given logger.
      Parameters:
      logger - the logger to which the formatter will be added