I am trying to localize the messages in a java application. I am using ResourceBundle loading based on Locale.
I want the messages on console to be localized and messages in log files to be in English.
What I am doing is this:
if (bundle != null) {
MessageFormat formatter = new MessageFormat(bundle.getString(message));
Object [] messageArgument = new Object[] {"arg1"};
logger.info(formatter.format(messageArgument));
}
I have set the ConsoleHandler threshold to INFO.
The issue is, now even the info log file will contain localized message along with the console.
Is there a way to put English messages to log file and localized messages to console?
Edit: complete rewrite
Normally when logging a string is passed to the logger which is already localized and cannot be translated after this. However the type for the message in log4j is actual Object and only later within the framework it is converted to an actual string. This is done by log4j before the message is passed on to the appenders but it looks like the appender can still get at the original object. So it would seem to be possible to write custom appenders for log4j in combination with a custom message type that would give the behaviour you want but it will be complex.
I think you will be better of putting a layer on top of the console and log4j and just let that handle sending a localized message to the console directly and sending an english message to log4j.