[
https://issues.jboss.org/browse/LOGTOOL-116?page=com.atlassian.jira.plugi...
]
James Perkins commented on LOGTOOL-116:
---------------------------------------
Just for an example here is a simple interface and the generated implementation.
{code:java|title=ValidLogger.java}
@MessageLogger(projectCode = AbstractLoggerTest.PROJECT_CODE)
public interface ValidLogger {
ValidLogger LOGGER = Logger.getMessageLogger(ValidLogger.class,
AbstractLoggerTest.CATEGORY);
/**
* Logs an error message indicating there was a processing error.
*
* @param cause the cause of the error.
* @param moduleName the module that caused the error.
*/
@LogMessage(level = Level.ERROR)
@Message(id = 201, value = "Processing error in module '%s'")
void processingError(@Cause Throwable cause, String moduleName);
/**
* Logs an error message indicating a processing error.
*
* @param on the object the error occurred on
* @param message the error message
*/
@LogMessage(level = Level.ERROR)
@Message(id = 203, value = "Processing error on '%s' with error
'%s'")
void processingError(Object on, String message);
}
{code}
{code:java|title=ValidLogger_$logger.java}
@Generated(value =
"org.jboss.logging.processor.generator.model.MessageLoggerImplementor", date =
"2016-11-15T13:34:22-0800")
public class ValidLogger_$logger implements ValidLogger, Serializable {
private static final long serialVersionUID = 1L;
private static final String FQCN = ValidLogger_$logger.class.getName();
public ValidLogger_$logger(final Logger log) {
this.log = log;
}
protected final Logger log;
@Override
public final void processingError(final Throwable cause, final String moduleName) {
log.logf(FQCN, ERROR, cause, processingError1$str(), moduleName);
}
private static final String processingError1 = "LOGL000201: Processing error in
module '%s'";
protected String processingError1$str() {
return processingError1;
}
@Override
public final void processingError(final Object on, final String message) {
log.logf(FQCN, ERROR, null, processingError2$str(), on, message);
}
private static final String processingError2 = "LOGL000203: Processing error on
'%s' with error '%s'";
protected String processingError2$str() {
return processingError2;
}
}
{code}
Locale is not used in the actual string format.
-----------------------------------------------
Key: LOGTOOL-116
URL:
https://issues.jboss.org/browse/LOGTOOL-116
Project: Log Tool
Issue Type: Bug
Affects Versions: 2.0.1.Final
Reporter: David Lloyd
Assignee: James Perkins
Priority: Minor
Fix For: 2.1.0.Alpha1
The {{String.format()}} method accepts a Locale parameter. We should be using the Locale
of the implementation class. Since the format method is called from a final method, we
need a polymorphic way of getting the Locale instance; therefore, a protected method
should be added to the generated base class like this:
{code}
protected Locale getLoggingLocale() {
return Locale.ROOT;
}
{code}
Then each subclass should return a locale object specific to that class. The locale
object returned should either be one of the following:
* Locale.CANADA - for "en_CA"
* Locale.CANADA_FRENCH - for "fr_CA"
* Locale.CHINESE - for "zh"
* Locale.ENGLISH - for "en"
* Locale.FRANCE - for "fr_FR"
* Locale.FRENCH - for "fr"
* Locale.GERMAN - for "de"
* Locale.GERMANY - for "de_DE"
* Locale.ITALIAN - for "it"
* Locale.ITALY - for "it_IT"
* Locale.JAPAN - for "ja_JP"
* Locale.JAPANESE - for "ja"
* Locale.KOREA - for "ko_KR"
* Locale.KOREAN - for "ko"
* Locale.SIMPLIFIED_CHINESE - for "zh_CN"
* Locale.TRADITIONAL_CHINESE - for "zh_TW"
* Locale.UK - for "en_GB"
* Locale.US - for "en_US"
If the locale is not one of the above, then the correct Locale should be created in a
private constant field of the class like this:
{code}
private static final Locale LOCALE = new Locale("hu");
// or...
private static final Locale LOCALE = new Locale("hu", "HU");
// or...
private static final Locale LOCALE = new Locale("hu", "HU",
"technl");
// ...and then...
@Override
protected Locale getLoggingLocale() {
return LOCALE;
}
{code}
Finally, all calls to {{format()}} should be rewritten to use the locale *from the
method* like this:
{code}
final NamingException result = new
NamingException(String.format(getLoggingLocale(), objectFromReference$str()));
{code}
--
This message was sent by Atlassian JIRA
(v7.2.3#72005)