Formats a {@code LogRecord} object into a localized string
representation. This is a convenience method for subclasses of {@code
Formatter}.
The message string is firstly localized using the {@code ResourceBundle}
object associated with the supplied {@code LogRecord}.
Notice : if message contains "{0", then java.text.MessageFormat is used.
Otherwise no formatting is performed.
String pattern = r.getMessage();
ResourceBundle rb = null;
// try to localize the message string first
if (null != (rb = r.getResourceBundle())) {
try {
pattern = rb.getString(pattern);
} catch (Exception e) {
pattern = r.getMessage();
}
}
if (null != pattern) {
Object[] params = r.getParameters();
/*
* if the message contains "{0", use java.text.MessageFormat to
* format the string
*/
if (pattern.indexOf("{0") >= 0 && null != params //$NON-NLS-1$
&& params.length > 0) {
try {
pattern = MessageFormat.format(pattern, params);
} catch (IllegalArgumentException e) {
pattern = r.getMessage();
}
}
}
return pattern;