[jboss-svn-commits] JBoss Common SVN: r3539 - in jboss-logmanager/trunk/src/main/java/org/jboss/logmanager: formatters and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Thu Sep 24 15:24:49 EDT 2009


Author: david.lloyd at jboss.com
Date: 2009-09-24 15:24:49 -0400 (Thu, 24 Sep 2009)
New Revision: 3539

Modified:
   jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/ExtLogRecord.java
   jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/formatters/FormatStringParser.java
   jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/formatters/Formatters.java
Log:
JBLOGGING-29: A separate formatting char for resource bundle key

Modified: jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/ExtLogRecord.java
===================================================================
--- jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/ExtLogRecord.java	2009-09-23 03:49:53 UTC (rev 3538)
+++ jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/ExtLogRecord.java	2009-09-24 19:24:49 UTC (rev 3539)
@@ -106,6 +106,7 @@
     private Map<String, String> mdcCopy;
     private int sourceLineNumber = -1;
     private String sourceFileName;
+    private String resourceKey;
     private String formattedMessage;
     private String threadName;
 
@@ -293,12 +294,26 @@
         return formattedMessage;
     }
 
+    /**
+     * Get the resource key, if any.  If the log message is not localized, then the key is {@code null}.
+     *
+     * @return the resource key
+     */
+    public String getResourceKey() {
+        if (formattedMessage == null) {
+            formatRecord();
+        }
+        return resourceKey;
+    }
+
     private String formatRecord() {
         final ResourceBundle bundle = getResourceBundle();
         String msg = getMessage();
         if (bundle != null) {
             try {
-                msg = bundle.getString(msg);
+                String locMsg = bundle.getString(msg);
+                resourceKey = msg;
+                msg = locMsg;
             } catch (MissingResourceException ex) {
                 // ignore
             }

Modified: jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/formatters/FormatStringParser.java
===================================================================
--- jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/formatters/FormatStringParser.java	2009-09-23 03:49:53 UTC (rev 3538)
+++ jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/formatters/FormatStringParser.java	2009-09-24 19:24:49 UTC (rev 3539)
@@ -97,6 +97,10 @@
                         stepList.add(Formatters.fileNameFormatStep(leftJustify, minimumWidth, maximumWidth));
                         break;
                     }
+                    case 'k': {
+                        stepList.add(Formatters.resourceKeyFormatStep(leftJustify, minimumWidth, maximumWidth));
+                        break;
+                    }
                     case 'l': {
                         stepList.add(Formatters.locationInformationFormatStep(leftJustify, minimumWidth, maximumWidth));
                         break;

Modified: jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/formatters/Formatters.java
===================================================================
--- jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/formatters/Formatters.java	2009-09-23 03:49:53 UTC (rev 3538)
+++ jboss-logmanager/trunk/src/main/java/org/jboss/logmanager/formatters/Formatters.java	2009-09-24 19:24:49 UTC (rev 3539)
@@ -322,6 +322,23 @@
     }
 
     /**
+     * Create a format step which emits the log message resource key (if any) with the given justification rules.
+     *
+     * @param leftJustify {@code true} to left justify, {@code false} to right justify
+     * @param minimumWidth the minimum field width, or 0 for none
+     * @param maximumWidth the maximum field width (must be greater than {@code minimumFieldWidth}), or 0 for none
+     * @return the format step
+     */
+    public static FormatStep resourceKeyFormatStep(final boolean leftJustify, final int minimumWidth, final int maximumWidth) {
+        return new JustifyingFormatStep(leftJustify, minimumWidth, maximumWidth) {
+            public void renderRaw(final StringBuilder builder, final ExtLogRecord record) {
+                final String key = record.getResourceKey();
+                if (key != null) builder.append(key);
+            }
+        };
+    }
+
+    /**
      * Create a format step which emits the source method name with the given justification rules (NOTE: call stack
      * introspection introduces a significant performance penalty).
      *



More information about the jboss-svn-commits mailing list