Class MessageFormatter

java.lang.Object
org.apache.log4j.helpers.MessageFormatter

public final class MessageFormatter extends Object
Formats messages according to very simple rules. See format(String, Object) and format(String, Object, Object) for more details.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    private static final char
    Start of replacement block.
    private static final char
    End of replacement block.
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
    Private formatter since all methods and members are static.
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    format(String messagePattern, Object argument)
    Performs single argument substitution for the 'messagePattern' passed as parameter.
    static String
    format(String messagePattern, Object arg1, Object arg2)
    /** Performs a two argument substitution for the 'messagePattern' passed as parameter.

    Methods inherited from class java.lang.Object

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

    • DELIM_START

      private static final char DELIM_START
      Start of replacement block.
      See Also:
    • DELIM_STOP

      private static final char DELIM_STOP
      End of replacement block.
      See Also:
  • Constructor Details

    • MessageFormatter

      private MessageFormatter()
      Private formatter since all methods and members are static.
  • Method Details

    • format

      public static String format(String messagePattern, Object argument)
      Performs single argument substitution for the 'messagePattern' passed as parameter.

      For example, MessageFormatter.format("Hi {}.", "there"); will return the string "Hi there.".

      The {} pair is called the formatting element. It serves to designate the location where the argument needs to be inserted within the pattern.
      Parameters:
      messagePattern - The message pattern which will be parsed and formatted
      argument - The argument to be inserted instead of the formatting element
      Returns:
      The formatted message
    • format

      public static String format(String messagePattern, Object arg1, Object arg2)
      /** Performs a two argument substitution for the 'messagePattern' passed as parameter.

      For example, MessageFormatter.format("Hi {}. My name is {}.", "there", "David"); will return the string "Hi there. My name is David.".

      The '{}' pair is called a formatting element. It serves to designate the location where the arguments need to be inserted within the message pattern.
      Parameters:
      messagePattern - The message pattern which will be parsed and formatted
      arg1 - The first argument to replace the first formatting element
      arg2 - The second argument to replace the second formatting element
      Returns:
      The formatted message