- java.lang.Object
-
- org.apache.logging.log4j.message.LocalizedMessage
-
- All Implemented Interfaces:
LoggerNameAwareMessage
,Message
public class LocalizedMessage extends Object implements Message, LoggerNameAwareMessage
Provides some level of compatibility with Log4j 1.x and convenience but is not the recommended way to Localize messages.The recommended way to localize messages is to log a message id. Log events should then be recorded without formatting into a data store. The application that is used to read the events and display them to the user can then localize and format the messages for the end user.
-
-
Constructor Summary
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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.protected ResourceBundle
getResourceBundle(String rbBaseName, Locale resourceBundleLocale, boolean loop)
Override this to use a ResourceBundle.Control in Java 6Throwable
getThrowable()
Gets the throwable, if any.void
setLoggerName(String name)
Set the name of the Logger.String
toString()
-
-
-
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(ResourceBundle bundle, String key, Object[] arguments)
-
LocalizedMessage
public LocalizedMessage(String baseName, Locale locale, String key, Object[] arguments)
-
LocalizedMessage
public LocalizedMessage(ResourceBundle bundle, Locale locale, String key, Object[] arguments)
-
LocalizedMessage
public LocalizedMessage(ResourceBundle bundle, String key)
- Parameters:
bundle
- The ResourceBundle for this message.key
- The key of the message in the bundle.- Since:
- 2.8
-
LocalizedMessage
public LocalizedMessage(ResourceBundle bundle, String key, Object arg)
-
LocalizedMessage
public LocalizedMessage(ResourceBundle bundle, Locale locale, String key, Object arg)
-
LocalizedMessage
public LocalizedMessage(ResourceBundle bundle, String key, Object arg1, Object arg2)
-
LocalizedMessage
public LocalizedMessage(String baseName, Locale locale, String key, Object arg1, Object arg2)
-
LocalizedMessage
public LocalizedMessage(ResourceBundle bundle, 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 interfaceLoggerNameAwareMessage
- Parameters:
name
- The name of the Logger.
-
getLoggerName
public String getLoggerName()
Returns the name of the Logger.- Specified by:
getLoggerName
in interfaceLoggerNameAwareMessage
- 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 interfaceMessage
- Returns:
- The formatted message String.
-
getFormat
public String getFormat()
Description copied from interface:Message
Gets the format portion of the Message. This may be an implementation-specific template string for interpolating the message parameters.
-
getParameters
public Object[] getParameters()
Description copied from interface:Message
Gets parameter values, if any.- Specified by:
getParameters
in interfaceMessage
- 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 interfaceMessage
- Returns:
- the throwable or null.
-
getResourceBundle
protected ResourceBundle getResourceBundle(String rbBaseName, Locale resourceBundleLocale, boolean loop)
Override this to use a ResourceBundle.Control in Java 6- Parameters:
rbBaseName
- The base name of the resource bundle, a fully qualified class name.resourceBundleLocale
- 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.
-
-