org.apache.logging.log4j.message
Class LocalizedMessage

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

public class LocalizedMessage
extends Object
implements Message, 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

Constructor Summary
LocalizedMessage(Locale locale, String key, Object arg)
           
LocalizedMessage(Locale locale, String key, Object[] arguments)
           
LocalizedMessage(Locale locale, String key, Object arg1, Object arg2)
           
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, String key, Object arg)
           
LocalizedMessage(ResourceBundle bundle, String key, Object[] arguments)
           
LocalizedMessage(ResourceBundle bundle, String key, Object arg1, Object arg2)
           
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 messagePattern, Object arg)
           
LocalizedMessage(String messagePattern, Object[] arguments)
          Constructor with message pattern and arguments.
LocalizedMessage(String messagePattern, Object arg1, Object arg2)
           
LocalizedMessage(String bundleId, String key, Object arg)
           
LocalizedMessage(String bundleId, String key, Object[] arguments)
           
LocalizedMessage(String bundleId, String key, Object arg1, Object arg2)
           
 
Method Summary
protected  ResourceBundle getBundle(String key, Locale locale, boolean loop)
          Override this to use a ResourceBundle.Control in Java 6
 String getFormat()
          Gets the format portion of the Message.
 String getFormattedMessage()
          Returns the formatted message after looking up the format in the resource bundle.
 String getLoggerName()
          Returns the name of the Logger.
 Object[] getParameters()
          Gets parameter values, if any.
 Throwable getThrowable()
          Gets the throwable, if any.
 void setLoggerName(String name)
          Set the name of the Logger.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LocalizedMessage

public LocalizedMessage(String messagePattern,
                        Object[] arguments)
Constructor with message pattern and arguments.

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()
Returns the name of the Logger.

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

getFormattedMessage

public String getFormattedMessage()
Returns the formatted message after looking up the format in the resource bundle.

Specified by:
getFormattedMessage in interface Message
Returns:
The formatted message String.

getFormat

public String getFormat()
Description copied from interface: Message
Gets the format portion of the Message.

Specified by:
getFormat in interface Message
Returns:
The message format. Some implementations, such as ParameterizedMessage, will use this as the message "pattern". Other Messages may simply return an empty String.

getParameters

public Object[] getParameters()
Description copied from interface: Message
Gets parameter values, if any.

Specified by:
getParameters in interface Message
Returns:
An array of parameter values or null.

getThrowable

public Throwable getThrowable()
Description copied from interface: Message
Gets the throwable, if any.

Specified by:
getThrowable in interface Message
Returns:
the throwable or null.

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-2013 Apache Software Foundation. All Rights Reserved.
Apache Logging, Apache Log4j, Log4j, Apache, the Apache feather logo, the Apache Logging project logo, and the Apache Log4j logo are trademarks of The Apache Software Foundation.