org.apache.logging.log4j.message
Class LocalizedMessage

java.lang.Object
  extended by org.apache.logging.log4j.message.ParameterizedMessage
      extended by org.apache.logging.log4j.message.LocalizedMessage
All Implemented Interfaces:
Serializable, LoggerNameAwareMessage, Message

public class LocalizedMessage
extends ParameterizedMessage
implements LoggerNameAwareMessage

This class is not the recommended way to Localize messages. It is provided to provide some level of compatibility with Log4j 1.x. The recommended way to localize messages is to simply log a message id. Log events should then be recorded without formatting into some kind of data store. The application that is used to read the events and display them to the user should also localize and format the messages for the end user.

See Also:
Serialized Form

Field Summary
 
Fields inherited from class org.apache.logging.log4j.message.ParameterizedMessage
ERROR_MSG_SEPARATOR, ERROR_PREFIX, ERROR_SEPARATOR, ERROR_SUFFIX, RECURSION_PREFIX, RECURSION_SUFFIX
 
Constructor Summary
LocalizedMessage()
          The basic constructor.
LocalizedMessage(Locale locale, String key, Object arg)
           
LocalizedMessage(Locale locale, String key, Object[] arguments)
           
LocalizedMessage(Locale locale, String key, Object arg1, Object arg2)
           
LocalizedMessage(Locale locale, String key, String[] stringArgs, Throwable throwable)
           
LocalizedMessage(ResourceBundle bundle, Locale locale, String key, Object arg)
           
LocalizedMessage(ResourceBundle bundle, Locale locale, String key, Object[] arguments)
           
LocalizedMessage(ResourceBundle bundle, Locale locale, String key, Object arg1, Object arg2)
           
LocalizedMessage(ResourceBundle bundle, Locale locale, String key, String[] stringArgs, Throwable throwable)
           
LocalizedMessage(ResourceBundle bundle, String key, Object arg)
           
LocalizedMessage(ResourceBundle bundle, String key, Object[] arguments)
           
LocalizedMessage(ResourceBundle bundle, String key, Object arg1, Object arg2)
           
LocalizedMessage(ResourceBundle bundle, String key, String[] stringArgs, Throwable throwable)
           
LocalizedMessage(String bundleId, Locale locale, String key, Object arg)
           
LocalizedMessage(String bundleId, Locale locale, String key, Object[] arguments)
           
LocalizedMessage(String bundleId, Locale locale, String key, Object arg1, Object arg2)
           
LocalizedMessage(String bundleId, Locale locale, String key, String[] stringArgs, Throwable throwable)
           
LocalizedMessage(String messagePattern, Object arg)
           
LocalizedMessage(String messagePattern, Object[] arguments)
          This method returns a LocalizedMessage which contains the arguments converted to String as well as an optional Throwable.
LocalizedMessage(String messagePattern, Object arg1, Object arg2)
           
LocalizedMessage(String messagePattern, String[] stringArgs, Throwable throwable)
           
LocalizedMessage(String bundleId, String key, Object arg)
           
LocalizedMessage(String bundleId, String key, Object[] arguments)
           
LocalizedMessage(String bundleId, String key, Object arg1, Object arg2)
           
LocalizedMessage(String bundleId, String key, String[] stringArgs, Throwable throwable)
           
 
Method Summary
 String formatMessage(String messagePattern, String[] args)
          Return the formatted message after looking up the format in the resource bundle.
protected  ResourceBundle getBundle(String key, Locale locale, boolean loop)
          Override this to use a ResourceBundle.Control in Java 6
 String getLoggerName()
          Return the name of the Logger.
 void setLoggerName(String name)
          Set the name of the Logger.
 
Methods inherited from class org.apache.logging.log4j.message.ParameterizedMessage
countArgumentPlaceholders, deepToString, equals, format, getFormattedMessage, getMessageFormat, getParameters, getThrowable, hashCode, identityToString, setMessageFormat, setParameters, setParameters, setThrowable, toString
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LocalizedMessage

public LocalizedMessage()
The basic constructor.


LocalizedMessage

public LocalizedMessage(String messagePattern,
                        String[] stringArgs,
                        Throwable throwable)

LocalizedMessage

public LocalizedMessage(String bundleId,
                        String key,
                        String[] stringArgs,
                        Throwable throwable)

LocalizedMessage

public LocalizedMessage(ResourceBundle bundle,
                        String key,
                        String[] stringArgs,
                        Throwable throwable)

LocalizedMessage

public LocalizedMessage(String bundleId,
                        Locale locale,
                        String key,
                        String[] stringArgs,
                        Throwable throwable)

LocalizedMessage

public LocalizedMessage(ResourceBundle bundle,
                        Locale locale,
                        String key,
                        String[] stringArgs,
                        Throwable throwable)

LocalizedMessage

public LocalizedMessage(Locale locale,
                        String key,
                        String[] stringArgs,
                        Throwable throwable)

LocalizedMessage

public LocalizedMessage(String messagePattern,
                        Object[] arguments)

This method returns a LocalizedMessage which contains the arguments converted to String as well as an optional Throwable.

If the last argument is a Throwable and is NOT used up by a placeholder in the message pattern it is returned in LocalizedMessage.getThrowable() and won't be contained in the created String[].
If it is used up ParameterizedMessage.getThrowable() will return null even if the last argument was a Throwable!

Parameters:
messagePattern - the message pattern that to be checked for placeholders.
arguments - the argument array to be converted.

LocalizedMessage

public LocalizedMessage(String bundleId,
                        String key,
                        Object[] arguments)

LocalizedMessage

public LocalizedMessage(ResourceBundle bundle,
                        String key,
                        Object[] arguments)

LocalizedMessage

public LocalizedMessage(String bundleId,
                        Locale locale,
                        String key,
                        Object[] arguments)

LocalizedMessage

public LocalizedMessage(ResourceBundle bundle,
                        Locale locale,
                        String key,
                        Object[] arguments)

LocalizedMessage

public LocalizedMessage(Locale locale,
                        String key,
                        Object[] arguments)

LocalizedMessage

public LocalizedMessage(String messagePattern,
                        Object arg)

LocalizedMessage

public LocalizedMessage(String bundleId,
                        String key,
                        Object arg)

LocalizedMessage

public LocalizedMessage(ResourceBundle bundle,
                        String key,
                        Object arg)

LocalizedMessage

public LocalizedMessage(String bundleId,
                        Locale locale,
                        String key,
                        Object arg)

LocalizedMessage

public LocalizedMessage(ResourceBundle bundle,
                        Locale locale,
                        String key,
                        Object arg)

LocalizedMessage

public LocalizedMessage(Locale locale,
                        String key,
                        Object arg)

LocalizedMessage

public LocalizedMessage(String messagePattern,
                        Object arg1,
                        Object arg2)

LocalizedMessage

public LocalizedMessage(String bundleId,
                        String key,
                        Object arg1,
                        Object arg2)

LocalizedMessage

public LocalizedMessage(ResourceBundle bundle,
                        String key,
                        Object arg1,
                        Object arg2)

LocalizedMessage

public LocalizedMessage(String bundleId,
                        Locale locale,
                        String key,
                        Object arg1,
                        Object arg2)

LocalizedMessage

public LocalizedMessage(ResourceBundle bundle,
                        Locale locale,
                        String key,
                        Object arg1,
                        Object arg2)

LocalizedMessage

public LocalizedMessage(Locale locale,
                        String key,
                        Object arg1,
                        Object arg2)
Method Detail

setLoggerName

public void setLoggerName(String name)
Set the name of the Logger.

Specified by:
setLoggerName in interface LoggerNameAwareMessage
Parameters:
name - The name of the Logger.

getLoggerName

public String getLoggerName()
Return the name of the Logger.

Specified by:
getLoggerName in interface LoggerNameAwareMessage
Returns:
the name of the Logger.

formatMessage

public String formatMessage(String messagePattern,
                            String[] args)
Return the formatted message after looking up the format in the resource bundle.

Overrides:
formatMessage in class ParameterizedMessage
Parameters:
messagePattern - The key for the resource bundle or the pattern if the bundle doesn't contain the key.
args - The parameters.
Returns:
The formatted message String.

getBundle

protected ResourceBundle getBundle(String key,
                                   Locale locale,
                                   boolean loop)
Override this to use a ResourceBundle.Control in Java 6

Parameters:
key - The key to the bundle.
locale - The locale to use when formatting the message.
loop - If true the key will be treated as a package or class name and a resource bundle will be located based on all or part of the package name. If false the key is expected to be the exact bundle id.
Returns:
The ResourceBundle.


Copyright © 1999-2012 Apache Software Foundation. All Rights Reserved.