geronimo-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Cabrera, Alan" <>
Subject RE: [i18n] Hardcoded message strings
Date Tue, 19 Aug 2003 18:34:01 GMT
> -----Original Message-----
> From: Alex Blewitt [] 
> Bear also in mind that if you are logging something, then it may be 
> less efficient to say:
> String pattern = "You have %{0} items left";
> String message = format.pattern(1); // or similar syntax such as 
> TextFormat?
> log(message);
> than it would be to say
> String pattern = "You have %{0} items left";
> log(pattern,1);
> That way, the logger can take advantage of the fact that it's 
> a message 
> format, and not do any applications until the message needs logging, 
> and when it does, it doesn't need to convert everything to one string 
> first, but can write out the template as three separate log messages 
> (log("You have "); log("1"); log (" items left");)

Good point. In OpenEJB we have a Messages class to simplify i18n messages
and a logger that gives one a finer degree of control over i18n formatting.

Static final Messages _msg = new Messages( "org.openejb.util.resources" );

if ( initialized ) {
    String msg = messages.message( "startup.alreadyInitialzied", new Date()
    logger.error( msg );
    throw new OpenEJBException( msg );
} else { "startup.starting", new Date() );

The former message needs to be formatted anyway, since we're throwing an
exception.  The latter call to the logger will not format the message unless
info logging is turned on.

Concerning your statement about writing out the template as three separate
log messages, I do not see the advantage of this since the format seems to
work just fine and it seems to me that the logger would write the three
pieces on three lines.


      Visit our Internet site at 

Get closer to the financial markets with Reuters Messaging - for more
information and to register, visit <> 

Any views expressed in this message are those of  the  individual sender,
except  where  the sender specifically states them to be the views of The
Reuters Group.

View raw message