[jboss-svn-commits] JBoss Common SVN: r3084 - jboss-logmanager/trunk/src/main/java/org/jboss/logmanager.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Mon Mar 16 18:25:38 EDT 2009


Author: david.lloyd at jboss.com
Date: 2009-03-16 18:25:38 -0400 (Mon, 16 Mar 2009)
New Revision: 3084

Modified:
   jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/ExtLogRecord.java
Log:
Add centralized message formatting. (todo - support for java.util.Formatter?)

Modified: jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/ExtLogRecord.java
===================================================================
--- jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/ExtLogRecord.java	2009-03-16 22:00:59 UTC (rev 3083)
+++ jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/ExtLogRecord.java	2009-03-16 22:25:38 UTC (rev 3084)
@@ -23,8 +23,11 @@
 package org.jboss.logmanager;
 
 import java.util.Map;
+import java.util.ResourceBundle;
+import java.util.MissingResourceException;
 import java.io.ObjectOutputStream;
 import java.io.IOException;
+import java.text.MessageFormat;
 
 import java.util.logging.LogRecord;
 
@@ -79,10 +82,12 @@
 
     private Map<String, String> mdcCopy;
     private int sourceLineNumber = -1;
+    private String formattedMessage;
 
     private void writeObject(ObjectOutputStream oos) throws IOException {
         copyMdc();
         calculateCaller();
+        getFormattedMessage();
         oos.defaultWriteObject();
     }
 
@@ -203,4 +208,27 @@
         calculateCaller = false;
         super.setSourceMethodName(sourceMethodName);
     }
+
+    public String getFormattedMessage() {
+        if (formattedMessage == null) {
+            formattedMessage = formatRecord();
+        }
+        return formattedMessage;
+    }
+
+    private String formatRecord() {
+        final ResourceBundle bundle = getResourceBundle();
+        String msg = getMessage();
+        if (bundle != null) {
+            try {
+                msg = bundle.getString(msg);
+            } catch (MissingResourceException ex) {
+                // ignore
+            }
+        }
+        final Object[] parameters = getParameters();
+        return parameters != null &&
+                parameters.length > 0 &&
+                msg.indexOf('{') >= 0 ? MessageFormat.format(msg, parameters) : msg;
+    }
 }




More information about the jboss-svn-commits mailing list