[jboss-cvs] JBossAS SVN: r59261 - in projects/test/trunk/test/src/main/org/jboss/test/logging: . jdk

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Jan 2 01:32:30 EST 2007


Author: scott.stark at jboss.org
Date: 2007-01-02 01:32:26 -0500 (Tue, 02 Jan 2007)
New Revision: 59261

Added:
   projects/test/trunk/test/src/main/org/jboss/test/logging/jdk/
   projects/test/trunk/test/src/main/org/jboss/test/logging/jdk/AbsoluteTimeDateFormat.java
   projects/test/trunk/test/src/main/org/jboss/test/logging/jdk/DateTimeDateFormat.java
   projects/test/trunk/test/src/main/org/jboss/test/logging/jdk/FormattingInfo.java
   projects/test/trunk/test/src/main/org/jboss/test/logging/jdk/ISO8601DateFormat.java
   projects/test/trunk/test/src/main/org/jboss/test/logging/jdk/JDKConsoleLoggingPlugin.java
   projects/test/trunk/test/src/main/org/jboss/test/logging/jdk/PatternConverter.java
   projects/test/trunk/test/src/main/org/jboss/test/logging/jdk/PatternFormatter.java
   projects/test/trunk/test/src/main/org/jboss/test/logging/jdk/PatternParser.java
Modified:
   projects/test/trunk/test/src/main/org/jboss/test/logging/LoggingPlugin.java
Log:
Default to jdk based console logger if the default logger cannot be loaded.

Modified: projects/test/trunk/test/src/main/org/jboss/test/logging/LoggingPlugin.java
===================================================================
--- projects/test/trunk/test/src/main/org/jboss/test/logging/LoggingPlugin.java	2007-01-02 04:42:31 UTC (rev 59260)
+++ projects/test/trunk/test/src/main/org/jboss/test/logging/LoggingPlugin.java	2007-01-02 06:32:26 UTC (rev 59261)
@@ -21,6 +21,8 @@
 */
 package org.jboss.test.logging;
 
+import org.jboss.test.logging.jdk.JDKConsoleLoggingPlugin;
+
 /**
  * A LoggingPlugin.
  * 
@@ -43,8 +45,23 @@
    public static LoggingPlugin getInstance() throws Exception
    {
       String loggingClassName = System.getProperty("org.jboss.test.logging.LogginPlugin", "org.jboss.test.logging.Log4jLoggingPlugin");
-      Class loggingClass  = Thread.currentThread().getContextClassLoader().loadClass(loggingClassName);
-      return (LoggingPlugin) loggingClass.newInstance();
+      try
+      {
+         Class loggingClass  = Thread.currentThread().getContextClassLoader().loadClass(loggingClassName);
+         return (LoggingPlugin) loggingClass.newInstance();
+      }
+      catch(NoClassDefFoundError e)
+      {
+         // Default to JDK
+         LoggingPlugin plugin = new JDKConsoleLoggingPlugin();
+         return plugin;         
+      }
+      catch(ClassNotFoundException e)
+      {
+         // Default to JDK
+         LoggingPlugin plugin = new JDKConsoleLoggingPlugin();
+         return plugin;
+      }
    }
 
    /**

Added: projects/test/trunk/test/src/main/org/jboss/test/logging/jdk/AbsoluteTimeDateFormat.java
===================================================================
--- projects/test/trunk/test/src/main/org/jboss/test/logging/jdk/AbsoluteTimeDateFormat.java	2007-01-02 04:42:31 UTC (rev 59260)
+++ projects/test/trunk/test/src/main/org/jboss/test/logging/jdk/AbsoluteTimeDateFormat.java	2007-01-02 06:32:26 UTC (rev 59261)
@@ -0,0 +1,154 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.logging.jdk;
+
+import java.text.DateFormat;
+import java.text.FieldPosition;
+import java.text.ParsePosition;
+import java.util.Calendar;
+import java.util.TimeZone;
+import java.util.Date;
+
+/**
+ * Formats a {@link Date} in the format "HH:mm:ss,SSS" for example,
+ * "15:49:37,459".
+ *
+ * @author Ceki Gülcü
+ * @author Andrew Vajoczki
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 1958 $
+ */
+public class AbsoluteTimeDateFormat extends DateFormat
+{
+   private static final long serialVersionUID = 1;
+
+   /**
+    * String constant used to specify {@link
+    * org.apache.log4j.helpers.AbsoluteTimeDateFormat} in layouts. Current
+    * value is <b>ABSOLUTE</b>.
+    */
+   public final static String ABS_TIME_DATE_FORMAT = "ABSOLUTE";
+
+   /**
+    * String constant used to specify {@link
+    * org.apache.log4j.helpers.DateTimeDateFormat} in layouts.  Current
+    * value is <b>DATE</b>.
+    */
+   public final static String DATE_AND_TIME_DATE_FORMAT = "DATE";
+
+   /**
+    * String constant used to specify {@link
+    * org.apache.log4j.helpers.ISO8601DateFormat} in layouts. Current
+    * value is <b>ISO8601</b>.
+    */
+   public final static String ISO8601_DATE_FORMAT = "ISO8601";
+
+   public AbsoluteTimeDateFormat()
+   {
+      setCalendar(Calendar.getInstance());
+   }
+
+   public AbsoluteTimeDateFormat(TimeZone timeZone)
+   {
+      setCalendar(Calendar.getInstance(timeZone));
+   }
+
+   private static long previousTime;
+   private static char[] previousTimeWithoutMillis = new char[9]; // "HH:mm:ss."
+
+   /**
+    * Appends to <code>sbuf</code> the time in the format
+    * "HH:mm:ss,SSS" for example, "15:49:37,459"
+    *
+    * @param date          the date to format
+    * @param sbuf          the string buffer to write to
+    * @param fieldPosition remains untouched
+    */
+   public StringBuffer format(Date date, StringBuffer sbuf,
+      FieldPosition fieldPosition)
+   {
+
+      long now = date.getTime();
+      int millis = (int) (now % 1000);
+
+      if ((now - millis) != previousTime)
+      {
+         // We reach this point at most once per second
+         // across all threads instead of each time format()
+         // is called. This saves considerable CPU time.
+
+         calendar.setTime(date);
+
+         int start = sbuf.length();
+
+         int hour = calendar.get(Calendar.HOUR_OF_DAY);
+         if (hour < 10)
+         {
+            sbuf.append('0');
+         }
+         sbuf.append(hour);
+         sbuf.append(':');
+
+         int mins = calendar.get(Calendar.MINUTE);
+         if (mins < 10)
+         {
+            sbuf.append('0');
+         }
+         sbuf.append(mins);
+         sbuf.append(':');
+
+         int secs = calendar.get(Calendar.SECOND);
+         if (secs < 10)
+         {
+            sbuf.append('0');
+         }
+         sbuf.append(secs);
+         sbuf.append(',');
+
+         // store the time string for next time to avoid recomputation
+         sbuf.getChars(start, sbuf.length(), previousTimeWithoutMillis, 0);
+
+         previousTime = now - millis;
+      }
+      else
+      {
+         sbuf.append(previousTimeWithoutMillis);
+      }
+
+
+      if (millis < 100)
+         sbuf.append('0');
+      if (millis < 10)
+         sbuf.append('0');
+
+      sbuf.append(millis);
+      return sbuf;
+   }
+
+   /**
+    This method does not do anything but return <code>null</code>.
+    */
+   public Date parse(String s, ParsePosition pos)
+   {
+      return null;
+   }
+}

Added: projects/test/trunk/test/src/main/org/jboss/test/logging/jdk/DateTimeDateFormat.java
===================================================================
--- projects/test/trunk/test/src/main/org/jboss/test/logging/jdk/DateTimeDateFormat.java	2007-01-02 04:42:31 UTC (rev 59260)
+++ projects/test/trunk/test/src/main/org/jboss/test/logging/jdk/DateTimeDateFormat.java	2007-01-02 06:32:26 UTC (rev 59261)
@@ -0,0 +1,92 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.logging.jdk;
+
+import java.text.DateFormatSymbols;
+import java.text.FieldPosition;
+import java.text.ParsePosition;
+import java.util.TimeZone;
+import java.util.Calendar;
+import java.util.Date;
+
+/**
+ * Formats a {@link Date} in the format "dd MMM YYYY HH:mm:ss,SSS" for example,
+ * "06 Nov 1994 15:49:37,459".
+ *
+ * @author Ceki G&uuml;lc&uuml;
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 1958 $
+ */
+public class DateTimeDateFormat extends AbsoluteTimeDateFormat
+{
+   private static final long serialVersionUID = 1;
+
+   String[] shortMonths;
+
+   public DateTimeDateFormat()
+   {
+      super();
+      shortMonths = new DateFormatSymbols().getShortMonths();
+   }
+
+   public DateTimeDateFormat(TimeZone timeZone)
+   {
+      this();
+      setCalendar(Calendar.getInstance(timeZone));
+   }
+
+   /**
+    * Appends to <code>sbuf</code> the date in the format "dd MMM YYYY
+    * HH:mm:ss,SSS" for example, "06 Nov 1994 08:49:37,459".
+    *
+    * @param sbuf the string buffer to write to
+    */
+   public StringBuffer format(Date date, StringBuffer sbuf,
+      FieldPosition fieldPosition)
+   {
+
+      calendar.setTime(date);
+
+      int day = calendar.get(Calendar.DAY_OF_MONTH);
+      if (day < 10)
+         sbuf.append('0');
+      sbuf.append(day);
+      sbuf.append(' ');
+      sbuf.append(shortMonths[calendar.get(Calendar.MONTH)]);
+      sbuf.append(' ');
+
+      int year = calendar.get(Calendar.YEAR);
+      sbuf.append(year);
+      sbuf.append(' ');
+
+      return super.format(date, sbuf, fieldPosition);
+   }
+
+   /**
+    * This method does not do anything but return <code>null</code>.
+    */
+   public Date parse(java.lang.String s, ParsePosition pos)
+   {
+      return null;
+   }
+}
+

Added: projects/test/trunk/test/src/main/org/jboss/test/logging/jdk/FormattingInfo.java
===================================================================
--- projects/test/trunk/test/src/main/org/jboss/test/logging/jdk/FormattingInfo.java	2007-01-02 04:42:31 UTC (rev 59260)
+++ projects/test/trunk/test/src/main/org/jboss/test/logging/jdk/FormattingInfo.java	2007-01-02 06:32:26 UTC (rev 59261)
@@ -0,0 +1,50 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.logging.jdk;
+
+/**
+ * FormattingInfo instances contain the information obtained when parsing
+ * formatting modifiers in conversion modifiers.
+ *
+ * @author <a href=mailto:jim_cakalic at na.biomerieux.com>Jim Cakalic</a>
+ * @author Ceki G&uuml;lc&uuml;
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 1958 $
+ */
+public class FormattingInfo
+{
+   int min = -1;
+   int max = 0x7FFFFFFF;
+   boolean leftAlign = false;
+
+   void reset()
+   {
+      min = -1;
+      max = 0x7FFFFFFF;
+      leftAlign = false;
+   }
+
+   void dump()
+   {
+      System.err.println("min=" + min + ", max=" + max + ", leftAlign=" + leftAlign);
+   }
+}

Added: projects/test/trunk/test/src/main/org/jboss/test/logging/jdk/ISO8601DateFormat.java
===================================================================
--- projects/test/trunk/test/src/main/org/jboss/test/logging/jdk/ISO8601DateFormat.java	2007-01-02 04:42:31 UTC (rev 59260)
+++ projects/test/trunk/test/src/main/org/jboss/test/logging/jdk/ISO8601DateFormat.java	2007-01-02 06:32:26 UTC (rev 59261)
@@ -0,0 +1,191 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.logging.jdk;
+
+import java.util.TimeZone;
+import java.util.Date;
+import java.util.Calendar;
+import java.text.FieldPosition;
+import java.text.ParsePosition;
+
+// Contributors: Arndt Schoenewald <arndt at ibm23093i821.mc.schoenewald.de>
+
+/**
+ * Formats a {@link java.util.Date} in the format "YYYY-mm-dd HH:mm:ss,SSS" for example
+ * "1999-11-27 15:49:37,459".
+ * <p/>
+ * <p>Refer to the <a
+ * href=http://www.cl.cam.ac.uk/~mgk25/iso-time.html>summary of the
+ * International Standard Date and Time Notation</a> for more
+ * information on this format.
+ *
+ * @author Ceki G&uuml;lc&uuml;
+ * @author Andrew Vajoczki
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 1958 $
+ */
+public class ISO8601DateFormat extends AbsoluteTimeDateFormat
+{
+   private static final long serialVersionUID = 1;
+
+   public ISO8601DateFormat()
+   {
+   }
+
+   public ISO8601DateFormat(TimeZone timeZone)
+   {
+      super(timeZone);
+   }
+
+   static private long lastTime;
+   static private char[] lastTimeString = new char[20];
+
+   /**
+    * Appends a date in the format "YYYY-mm-dd HH:mm:ss,SSS"
+    * to <code>sbuf</code>. For example: "1999-11-27 15:49:37,459".
+    *
+    * @param sbuf the <code>StringBuffer</code> to write to
+    */
+   public StringBuffer format(Date date, StringBuffer sbuf,
+      FieldPosition fieldPosition)
+   {
+
+      long now = date.getTime();
+      int millis = (int) (now % 1000);
+
+      if ((now - millis) != lastTime)
+      {
+         // We reach this point at most once per second
+         // across all threads instead of each time format()
+         // is called. This saves considerable CPU time.
+
+         calendar.setTime(date);
+
+         int start = sbuf.length();
+
+         int year = calendar.get(Calendar.YEAR);
+         sbuf.append(year);
+
+         String month;
+         switch (calendar.get(Calendar.MONTH))
+         {
+            case Calendar.JANUARY:
+               month = "-01-";
+               break;
+            case Calendar.FEBRUARY:
+               month = "-02-";
+               break;
+            case Calendar.MARCH:
+               month = "-03-";
+               break;
+            case Calendar.APRIL:
+               month = "-04-";
+               break;
+            case Calendar.MAY:
+               month = "-05-";
+               break;
+            case Calendar.JUNE:
+               month = "-06-";
+               break;
+            case Calendar.JULY:
+               month = "-07-";
+               break;
+            case Calendar.AUGUST:
+               month = "-08-";
+               break;
+            case Calendar.SEPTEMBER:
+               month = "-09-";
+               break;
+            case Calendar.OCTOBER:
+               month = "-10-";
+               break;
+            case Calendar.NOVEMBER:
+               month = "-11-";
+               break;
+            case Calendar.DECEMBER:
+               month = "-12-";
+               break;
+            default:
+               month = "-NA-";
+               break;
+         }
+         sbuf.append(month);
+
+         int day = calendar.get(Calendar.DAY_OF_MONTH);
+         if (day < 10)
+            sbuf.append('0');
+         sbuf.append(day);
+
+         sbuf.append(' ');
+
+         int hour = calendar.get(Calendar.HOUR_OF_DAY);
+         if (hour < 10)
+         {
+            sbuf.append('0');
+         }
+         sbuf.append(hour);
+         sbuf.append(':');
+
+         int mins = calendar.get(Calendar.MINUTE);
+         if (mins < 10)
+         {
+            sbuf.append('0');
+         }
+         sbuf.append(mins);
+         sbuf.append(':');
+
+         int secs = calendar.get(Calendar.SECOND);
+         if (secs < 10)
+         {
+            sbuf.append('0');
+         }
+         sbuf.append(secs);
+
+         sbuf.append(',');
+
+         // store the time string for next time to avoid recomputation
+         sbuf.getChars(start, sbuf.length(), lastTimeString, 0);
+         lastTime = now - millis;
+      }
+      else
+      {
+         sbuf.append(lastTimeString);
+      }
+
+
+      if (millis < 100)
+         sbuf.append('0');
+      if (millis < 10)
+         sbuf.append('0');
+
+      sbuf.append(millis);
+      return sbuf;
+   }
+
+   /**
+    * This method does not do anything but return <code>null</code>.
+    */
+   public Date parse(java.lang.String s, ParsePosition pos)
+   {
+      return null;
+   }
+}

Added: projects/test/trunk/test/src/main/org/jboss/test/logging/jdk/JDKConsoleLoggingPlugin.java
===================================================================
--- projects/test/trunk/test/src/main/org/jboss/test/logging/jdk/JDKConsoleLoggingPlugin.java	2007-01-02 04:42:31 UTC (rev 59260)
+++ projects/test/trunk/test/src/main/org/jboss/test/logging/jdk/JDKConsoleLoggingPlugin.java	2007-01-02 06:32:26 UTC (rev 59261)
@@ -0,0 +1,53 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.logging.jdk;
+
+import java.util.logging.ConsoleHandler;
+import java.util.logging.Level;
+import java.util.logging.Logger;
+
+import org.jboss.test.logging.LoggingPlugin;
+
+/**
+ * A LoggingPlugin that uses the jdk logging ConsoleHandler
+ * 
+ * @author Scott.Stark at jboss.org
+ * @version $Revision:$
+ */
+public class JDKConsoleLoggingPlugin extends LoggingPlugin
+{
+   ConsoleHandler appender;
+
+   public void enableTrace(String name)
+   {
+      Logger.getLogger(name).setLevel(Level.FINEST);
+   }
+
+   public void setUp() throws Exception
+   {
+      // Setup a console appender
+      appender = new ConsoleHandler();
+      PatternFormatter layout = new PatternFormatter("%r %-5p [%c{1}] %m%n");
+      appender.setFormatter(layout);
+   }
+
+}

Added: projects/test/trunk/test/src/main/org/jboss/test/logging/jdk/PatternConverter.java
===================================================================
--- projects/test/trunk/test/src/main/org/jboss/test/logging/jdk/PatternConverter.java	2007-01-02 04:42:31 UTC (rev 59260)
+++ projects/test/trunk/test/src/main/org/jboss/test/logging/jdk/PatternConverter.java	2007-01-02 06:32:26 UTC (rev 59261)
@@ -0,0 +1,124 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.logging.jdk;
+
+import java.util.logging.LogRecord;
+
+/**
+ * <p>PatternConverter is an abtract class that provides the
+ * formatting functionality that derived classes need.
+ * <p/>
+ * <p>Conversion specifiers in a conversion patterns are parsed to
+ * individual PatternConverters. Each of which is responsible for
+ * converting a logging event in a converter specific manner.
+ *
+ * @author <a href="mailto:cakalijp at Maritz.com">James P. Cakalic</a>
+ * @author Ceki G&uuml;lc&uuml;
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 1958 $
+ */
+public abstract class PatternConverter
+{
+   public PatternConverter next;
+   int min = -1;
+   int max = 0x7FFFFFFF;
+   boolean leftAlign = false;
+
+   protected PatternConverter()
+   {
+   }
+
+   protected PatternConverter(FormattingInfo fi)
+   {
+      min = fi.min;
+      max = fi.max;
+      leftAlign = fi.leftAlign;
+   }
+
+   /**
+    * Derived pattern converters must override this method in order to
+    * convert conversion specifiers in the correct way.
+    */
+   abstract
+   protected String convert(LogRecord event);
+
+   /**
+    * A template method for formatting in a converter specific way.
+    */
+   public void format(StringBuffer sbuf, LogRecord e)
+   {
+      String s = convert(e);
+
+      if (s == null)
+      {
+         if (0 < min)
+            spacePad(sbuf, min);
+         return;
+      }
+
+      int len = s.length();
+
+      if (len > max)
+         sbuf.append(s.substring(len - max));
+      else if (len < min)
+      {
+         if (leftAlign)
+         {
+            sbuf.append(s);
+            spacePad(sbuf, min - len);
+         }
+         else
+         {
+            spacePad(sbuf, min - len);
+            sbuf.append(s);
+         }
+      }
+      else
+         sbuf.append(s);
+   }
+
+   static String[] SPACES = {" ", "  ", "    ", "        ", //1,2,4,8 spaces
+      "                ", // 16 spaces
+      "                                "}; // 32 spaces
+
+   /**
+    * Fast space padding method.
+    */
+   public void spacePad(StringBuffer sbuf, int length)
+   {
+      while (length >= 32)
+      {
+         sbuf.append(SPACES[5]);
+         length -= 32;
+      }
+
+      for (int i = 4; i >= 0; i--)
+      {
+         if ((length & (1 << i)) != 0)
+         {
+            sbuf.append(SPACES[i]);
+         }
+      }
+   }
+
+}
+

Added: projects/test/trunk/test/src/main/org/jboss/test/logging/jdk/PatternFormatter.java
===================================================================
--- projects/test/trunk/test/src/main/org/jboss/test/logging/jdk/PatternFormatter.java	2007-01-02 04:42:31 UTC (rev 59260)
+++ projects/test/trunk/test/src/main/org/jboss/test/logging/jdk/PatternFormatter.java	2007-01-02 06:32:26 UTC (rev 59261)
@@ -0,0 +1,147 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.logging.jdk;
+
+import java.util.logging.Formatter;
+import java.util.logging.LogRecord;
+
+/**
+ * A log4j style pattern formatter.
+ * 
+ * @author <a href="mailto:cakalijp at Maritz.com">James P. Cakalic</a>
+ * @author Ceki G&uuml;lc&uuml;
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 1958 $
+ */
+public class PatternFormatter extends Formatter
+{
+
+   /**
+    * Default pattern string for log output. Currently set to the
+    * string <b>"%m%n"</b> which just prints the application supplied
+    * message.
+    */
+   public final static String DEFAULT_CONVERSION_PATTERN = "%m%n";
+
+   /**
+    * A conversion pattern equivalent to the TTCCCLayout.
+    * Current value is <b>%r [%t] %p %c %x - %m%n</b>.
+    */
+   public final static String TTCC_CONVERSION_PATTERN
+      = "%r [%t] %p %c %x - %m%n";
+
+
+   protected final int BUF_SIZE = 256;
+   protected final int MAX_CAPACITY = 1024;
+
+   private String pattern;
+
+   private PatternConverter head;
+
+   /**
+    * Constructs a PatternLayout using the DEFAULT_LAYOUT_PATTERN.
+    * <p/>
+    * The default pattern just produces the application supplied message.
+    */
+   public PatternFormatter()
+   {
+      this(DEFAULT_CONVERSION_PATTERN);
+   }
+
+   /**
+    * Constructs a PatternLayout using the supplied conversion pattern.
+    */
+   public PatternFormatter(String pattern)
+   {
+      this.pattern = pattern;
+      head = createPatternParser((pattern == null) ? DEFAULT_CONVERSION_PATTERN :
+         pattern).parse();
+   }
+
+   /**
+    * Set the <b>ConversionPattern</b> option. This is the string which
+    * controls formatting and consists of a mix of literal content and
+    * conversion specifiers.
+    */
+   public void setConversionPattern(String conversionPattern)
+   {
+      pattern = conversionPattern;
+      head = createPatternParser(conversionPattern).parse();
+   }
+
+   /**
+    * Returns the value of the <b>ConversionPattern</b> option.
+    */
+   public String getConversionPattern()
+   {
+      return pattern;
+   }
+
+   /**
+    * Does not do anything as options become effective
+    */
+   public void activateOptions()
+   {
+      // nothing to do.
+   }
+
+   /**
+    * The PatternLayout does not handle the throwable contained within
+    * {@link LoggingEvent LoggingEvents}. Thus, it returns
+    * <code>true</code>.
+    *
+    * @since 0.8.4
+    */
+   public boolean ignoresThrowable()
+   {
+      return true;
+   }
+
+   /**
+    * Returns PatternParser used to parse the conversion string. Subclasses
+    * may override this to return a subclass of PatternParser which recognize
+    * custom conversion characters.
+    *
+    * @since 0.9.0
+    */
+   protected PatternParser createPatternParser(String pattern)
+   {
+      return new PatternParser(pattern);
+   }
+
+
+   /**
+    * Produces a formatted string as specified by the conversion pattern.
+    */
+   public String format(LogRecord event)
+   {
+      // output buffer appended to when format() is invoked
+      StringBuffer sbuf = new StringBuffer(BUF_SIZE);
+      PatternConverter c = head;
+      while (c != null)
+      {
+         c.format(sbuf, event);
+         c = c.next;
+      }
+      return sbuf.toString();
+   }
+}

Added: projects/test/trunk/test/src/main/org/jboss/test/logging/jdk/PatternParser.java
===================================================================
--- projects/test/trunk/test/src/main/org/jboss/test/logging/jdk/PatternParser.java	2007-01-02 04:42:31 UTC (rev 59260)
+++ projects/test/trunk/test/src/main/org/jboss/test/logging/jdk/PatternParser.java	2007-01-02 06:32:26 UTC (rev 59261)
@@ -0,0 +1,622 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.logging.jdk;
+
+import java.text.DateFormat;
+import java.text.SimpleDateFormat;
+import java.util.Date;
+import java.util.logging.LogRecord;
+
+// Contributors:   Nelson Minar <(nelson at monkey.org>
+//                 Igor E. Poteryaev <jah at mail.ru>
+//                 Reinhard Deschler <reinhard.deschler at web.de>
+
+/**
+ * Most of the work of the PatternFormatter class
+ * is delegated to the PatternParser class.
+ * <p/>
+ * <p>It is this class that parses conversion patterns and creates
+ * a chained list of {@link OptionConverter OptionConverters}.
+ *
+ * @author <a href=mailto:"cakalijp at Maritz.com">James P. Cakalic</a>
+ * @author Ceki G&uuml;lc&uuml;
+ * @author Anders Kristensen
+ * @author Scott.Stark at jboss.org
+ * @version $Revision: 1958 $
+ */
+public class PatternParser
+{
+   public final static String LINE_SEP = System.getProperty("line.separator");
+
+   private static long startTime = System.currentTimeMillis();
+
+   private static final char ESCAPE_CHAR = '%';
+
+   private static final int LITERAL_STATE = 0;
+   private static final int CONVERTER_STATE = 1;
+   private static final int MINUS_STATE = 2;
+   private static final int DOT_STATE = 3;
+   private static final int MIN_STATE = 4;
+   private static final int MAX_STATE = 5;
+
+   static final int FULL_LOCATION_CONVERTER = 1000;
+   static final int METHOD_LOCATION_CONVERTER = 1001;
+   static final int CLASS_LOCATION_CONVERTER = 1002;
+   static final int LINE_LOCATION_CONVERTER = 1003;
+   static final int FILE_LOCATION_CONVERTER = 1004;
+
+   static final int RELATIVE_TIME_CONVERTER = 2000;
+   static final int THREAD_CONVERTER = 2001;
+   static final int LEVEL_CONVERTER = 2002;
+   static final int NDC_CONVERTER = 2003;
+   static final int MESSAGE_CONVERTER = 2004;
+   static final int THREAD_NAME_CONVERTER = 2005;
+
+   int state;
+   protected StringBuffer currentLiteral = new StringBuffer(32);
+   protected int patternLength;
+   protected int i;
+   PatternConverter head;
+   PatternConverter tail;
+   protected FormattingInfo formattingInfo = new FormattingInfo();
+   protected String pattern;
+
+   public PatternParser(String pattern)
+   {
+      this.pattern = pattern;
+      patternLength = pattern.length();
+      state = LITERAL_STATE;
+   }
+
+   private void addToList(PatternConverter pc)
+   {
+      if (head == null)
+      {
+         head = tail = pc;
+      }
+      else
+      {
+         tail.next = pc;
+         tail = pc;
+      }
+   }
+
+   protected String extractOption()
+   {
+      if ((i < patternLength) && (pattern.charAt(i) == '{'))
+      {
+         int end = pattern.indexOf('}', i);
+         if (end > i)
+         {
+            String r = pattern.substring(i + 1, end);
+            i = end + 1;
+            return r;
+         }
+      }
+      return null;
+   }
+
+
+   /**
+    * The option is expected to be in decimal and positive. In case of
+    * error, zero is returned.
+    */
+   protected int extractPrecisionOption()
+   {
+      String opt = extractOption();
+      int r = 0;
+      if (opt != null)
+      {
+         try
+         {
+            r = Integer.parseInt(opt);
+            if (r <= 0)
+            {
+               System.err.println("Precision option (" + opt + ") isn't a positive integer.");
+               r = 0;
+            }
+         }
+         catch (NumberFormatException e)
+         {
+            System.err.println("Category option '" + opt + "' not a decimal integer." + e.getMessage());
+         }
+      }
+      return r;
+   }
+
+   public PatternConverter parse()
+   {
+      char c;
+      i = 0;
+      while (i < patternLength)
+      {
+         c = pattern.charAt(i++);
+         switch (state)
+         {
+            case LITERAL_STATE:
+               // In literal state, the last char is always a literal.
+               if (i == patternLength)
+               {
+                  currentLiteral.append(c);
+                  continue;
+               }
+               if (c == ESCAPE_CHAR)
+               {
+                  // peek at the next char.
+                  switch (pattern.charAt(i))
+                  {
+                     case ESCAPE_CHAR:
+                        currentLiteral.append(c);
+                        i++; // move pointer
+                        break;
+                     case 'n':
+                        currentLiteral.append(LINE_SEP);
+                        i++; // move pointer
+                        break;
+                     default:
+                        if (currentLiteral.length() != 0)
+                        {
+                           addToList(new LiteralPatternConverter(
+                              currentLiteral.toString()));
+                           //LogLog.debug("Parsed LITERAL converter: \""
+                           //           +currentLiteral+"\".");
+                        }
+                        currentLiteral.setLength(0);
+                        currentLiteral.append(c); // append %
+                        state = CONVERTER_STATE;
+                        formattingInfo.reset();
+                  }
+               }
+               else
+               {
+                  currentLiteral.append(c);
+               }
+               break;
+            case CONVERTER_STATE:
+               currentLiteral.append(c);
+               switch (c)
+               {
+                  case '-':
+                     formattingInfo.leftAlign = true;
+                     break;
+                  case '.':
+                     state = DOT_STATE;
+                     break;
+                  default:
+                     if (c >= '0' && c <= '9')
+                     {
+                        formattingInfo.min = c - '0';
+                        state = MIN_STATE;
+                     }
+                     else
+                        finalizeConverter(c);
+               } // switch
+               break;
+            case MIN_STATE:
+               currentLiteral.append(c);
+               if (c >= '0' && c <= '9')
+                  formattingInfo.min = formattingInfo.min * 10 + (c - '0');
+               else if (c == '.')
+                  state = DOT_STATE;
+               else
+               {
+                  finalizeConverter(c);
+               }
+               break;
+            case DOT_STATE:
+               currentLiteral.append(c);
+               if (c >= '0' && c <= '9')
+               {
+                  formattingInfo.max = c - '0';
+                  state = MAX_STATE;
+               }
+               else
+               {
+                  System.err.println("Error occured in position " + i
+                     + ".\n Was expecting digit, instead got char \"" + c + "\".");
+                  state = LITERAL_STATE;
+               }
+               break;
+            case MAX_STATE:
+               currentLiteral.append(c);
+               if (c >= '0' && c <= '9')
+                  formattingInfo.max = formattingInfo.max * 10 + (c - '0');
+               else
+               {
+                  finalizeConverter(c);
+                  state = LITERAL_STATE;
+               }
+               break;
+         } // switch
+      } // while
+      if (currentLiteral.length() != 0)
+      {
+         addToList(new LiteralPatternConverter(currentLiteral.toString()));
+         //LogLog.debug("Parsed LITERAL converter: \""+currentLiteral+"\".");
+      }
+      return head;
+   }
+
+   protected void finalizeConverter(char c)
+   {
+      PatternConverter pc = null;
+      switch (c)
+      {
+         case 'c':
+            pc = new CategoryPatternConverter(formattingInfo,
+               extractPrecisionOption());
+            //LogLog.debug("CATEGORY converter.");
+            //formattingInfo.dump();
+            currentLiteral.setLength(0);
+            break;
+         case 'C':
+            pc = new ClassNamePatternConverter(formattingInfo,
+               extractPrecisionOption());
+            //LogLog.debug("CLASS_NAME converter.");
+            //formattingInfo.dump();
+            currentLiteral.setLength(0);
+            break;
+         case 'd':
+            String dateFormatStr = AbsoluteTimeDateFormat.ISO8601_DATE_FORMAT;
+            DateFormat df;
+            String dOpt = extractOption();
+            if (dOpt != null)
+               dateFormatStr = dOpt;
+
+            if (dateFormatStr.equalsIgnoreCase(
+               AbsoluteTimeDateFormat.ISO8601_DATE_FORMAT))
+               df = new ISO8601DateFormat();
+            else if (dateFormatStr.equalsIgnoreCase(
+               AbsoluteTimeDateFormat.ABS_TIME_DATE_FORMAT))
+               df = new AbsoluteTimeDateFormat();
+            else if (dateFormatStr.equalsIgnoreCase(
+               AbsoluteTimeDateFormat.DATE_AND_TIME_DATE_FORMAT))
+               df = new DateTimeDateFormat();
+            else
+            {
+               try
+               {
+                  df = new SimpleDateFormat(dateFormatStr);
+               }
+               catch (IllegalArgumentException e)
+               {
+                  System.err.println("Could not instantiate SimpleDateFormat with " +
+                     dateFormatStr + ", ex=" + e.getMessage());
+                  df = new ISO8601DateFormat();
+               }
+            }
+            pc = new DatePatternConverter(formattingInfo, df);
+            //LogLog.debug("DATE converter {"+dateFormatStr+"}.");
+            //formattingInfo.dump();
+            currentLiteral.setLength(0);
+            break;
+         case 'F':
+            pc = new LocationPatternConverter(formattingInfo,
+               FILE_LOCATION_CONVERTER);
+            //LogLog.debug("File name converter.");
+            //formattingInfo.dump();
+            currentLiteral.setLength(0);
+            break;
+         case 'l':
+            pc = new LocationPatternConverter(formattingInfo,
+               FULL_LOCATION_CONVERTER);
+            //LogLog.debug("Location converter.");
+            //formattingInfo.dump();
+            currentLiteral.setLength(0);
+            break;
+         case 'L':
+            pc = new LocationPatternConverter(formattingInfo,
+               LINE_LOCATION_CONVERTER);
+            //LogLog.debug("LINE NUMBER converter.");
+            //formattingInfo.dump();
+            currentLiteral.setLength(0);
+            break;
+         case 'm':
+            pc = new BasicPatternConverter(formattingInfo, MESSAGE_CONVERTER);
+            //LogLog.debug("MESSAGE converter.");
+            //formattingInfo.dump();
+            currentLiteral.setLength(0);
+            break;
+         case 'M':
+            pc = new LocationPatternConverter(formattingInfo,
+               METHOD_LOCATION_CONVERTER);
+            //LogLog.debug("METHOD converter.");
+            //formattingInfo.dump();
+            currentLiteral.setLength(0);
+            break;
+         case 'p':
+            pc = new BasicPatternConverter(formattingInfo, LEVEL_CONVERTER);
+            //LogLog.debug("LEVEL converter.");
+            //formattingInfo.dump();
+            currentLiteral.setLength(0);
+            break;
+         case 'r':
+            pc = new BasicPatternConverter(formattingInfo,
+               RELATIVE_TIME_CONVERTER);
+            //LogLog.debug("RELATIVE time converter.");
+            //formattingInfo.dump();
+            currentLiteral.setLength(0);
+            break;
+         case 't':
+            pc = new BasicPatternConverter(formattingInfo, THREAD_CONVERTER);
+            //LogLog.debug("THREAD converter.");
+            //formattingInfo.dump();
+            currentLiteral.setLength(0);
+            break;
+            /*case 'u':
+            if(i < patternLength) {
+         char cNext = pattern.charAt(i);
+         if(cNext >= '0' && cNext <= '9') {
+           pc = new UserFieldPatternConverter(formattingInfo, cNext - '0');
+           LogLog.debug("USER converter ["+cNext+"].");
+           formattingInfo.dump();
+           currentLiteral.setLength(0);
+           i++;
+         }
+         else
+           System.err.println("Unexpected char" +cNext+" at position "+i);
+            }
+            break;*/
+         case 'x':
+            pc = new BasicPatternConverter(formattingInfo, NDC_CONVERTER);
+            //LogLog.debug("NDC converter.");
+            currentLiteral.setLength(0);
+            break;
+         case 'X':
+            String xOpt = extractOption();
+            pc = new MDCPatternConverter(formattingInfo, xOpt);
+            currentLiteral.setLength(0);
+            break;
+         default:
+            System.err.println("Unexpected char [" + c + "] at position " + i
+               + " in conversion patterrn.");
+            pc = new LiteralPatternConverter(currentLiteral.toString());
+            currentLiteral.setLength(0);
+      }
+
+      addConverter(pc);
+   }
+
+   protected void addConverter(PatternConverter pc)
+   {
+      currentLiteral.setLength(0);
+      // Add the pattern converter to the list.
+      addToList(pc);
+      // Next pattern is assumed to be a literal.
+      state = LITERAL_STATE;
+      // Reset formatting info
+      formattingInfo.reset();
+   }
+
+   // ---------------------------------------------------------------------
+   //                      PatternConverters
+   // ---------------------------------------------------------------------
+
+   private static class BasicPatternConverter extends PatternConverter
+   {
+      int type;
+
+      BasicPatternConverter(FormattingInfo formattingInfo, int type)
+      {
+         super(formattingInfo);
+         this.type = type;
+      }
+
+      public String convert(LogRecord event)
+      {
+         switch (type)
+         {
+            case RELATIVE_TIME_CONVERTER:
+               return (Long.toString(event.getMillis() - startTime));
+            case THREAD_CONVERTER:
+               StringBuffer tmp = new StringBuffer("tid(");
+               tmp.append(event.getThreadID());
+               tmp.append(')');
+               return tmp.toString();
+            case THREAD_NAME_CONVERTER:
+               // @todo figure how to map the thread id to its name
+               return "null";
+            case LEVEL_CONVERTER:
+               return event.getLevel().toString();
+            case NDC_CONVERTER:
+               return "NDC not supported";
+            case MESSAGE_CONVERTER:
+            {
+               return event.getMessage();
+            }
+            default:
+               return null;
+         }
+      }
+   }
+
+   private static class LiteralPatternConverter extends PatternConverter
+   {
+      private String literal;
+
+      LiteralPatternConverter(String value)
+      {
+         literal = value;
+      }
+
+      public
+      final void format(StringBuffer sbuf, LogRecord event)
+      {
+         sbuf.append(literal);
+      }
+
+      public String convert(LogRecord event)
+      {
+         return literal;
+      }
+   }
+
+   private static class DatePatternConverter extends PatternConverter
+   {
+      private DateFormat df;
+      private Date date;
+
+      DatePatternConverter(FormattingInfo formattingInfo, DateFormat df)
+      {
+         super(formattingInfo);
+         date = new Date();
+         this.df = df;
+      }
+
+      public String convert(LogRecord event)
+      {
+         date.setTime(event.getMillis());
+         String converted = null;
+         try
+         {
+            converted = df.format(date);
+         }
+         catch (Exception ex)
+         {
+            System.err.println("Error occured while converting date, " + ex.getMessage());
+         }
+         return converted;
+      }
+   }
+
+   /**
+    * @todo how can this functionality be restored
+    */
+   private static class MDCPatternConverter extends PatternConverter
+   {
+      private String key;
+
+      MDCPatternConverter(FormattingInfo formattingInfo, String key)
+      {
+         super(formattingInfo);
+         this.key = key;
+      }
+
+      public String convert(LogRecord event)
+      {
+         Object val = null; // event.getMDC(key);
+         if (val == null)
+         {
+            return null;
+         }
+         else
+         {
+            return val.toString();
+         }
+      }
+   }
+
+
+   private class LocationPatternConverter extends PatternConverter
+   {
+      int type;
+
+      LocationPatternConverter(FormattingInfo formattingInfo, int type)
+      {
+         super(formattingInfo);
+         this.type = type;
+      }
+
+      public String convert(LogRecord event)
+      {
+         switch (type)
+         {
+            case FULL_LOCATION_CONVERTER:
+               return "Class: " + event.getSourceClassName() + "." + event.getSourceMethodName();
+            case METHOD_LOCATION_CONVERTER:
+               return event.getSourceMethodName();
+            case LINE_LOCATION_CONVERTER:
+               return "0";
+            case FILE_LOCATION_CONVERTER:
+               return event.getSourceClassName();
+            default:
+               return null;
+         }
+      }
+   }
+
+   private static abstract class NamedPatternConverter extends PatternConverter
+   {
+      int precision;
+
+      NamedPatternConverter(FormattingInfo formattingInfo, int precision)
+      {
+         super(formattingInfo);
+         this.precision = precision;
+      }
+
+      abstract String getFullyQualifiedName(LogRecord event);
+
+      public String convert(LogRecord event)
+      {
+         String n = getFullyQualifiedName(event);
+         if (precision <= 0)
+            return n;
+         else
+         {
+            int len = n.length();
+
+            // We substract 1 from 'len' when assigning to 'end' to avoid out of
+            // bounds exception in return r.substring(end+1, len). This can happen if
+            // precision is 1 and the category name ends with a dot.
+            int end = len - 1;
+            for (int i = precision; i > 0; i--)
+            {
+               end = n.lastIndexOf('.', end - 1);
+               if (end == -1)
+                  return n;
+            }
+            return n.substring(end + 1, len);
+         }
+      }
+   }
+
+   private class ClassNamePatternConverter extends NamedPatternConverter
+   {
+
+      ClassNamePatternConverter(FormattingInfo formattingInfo, int precision)
+      {
+         super(formattingInfo, precision);
+      }
+
+      String getFullyQualifiedName(LogRecord event)
+      {
+         return event.getSourceClassName();
+      }
+   }
+
+   private class CategoryPatternConverter extends NamedPatternConverter
+   {
+
+      CategoryPatternConverter(FormattingInfo formattingInfo, int precision)
+      {
+         super(formattingInfo, precision);
+      }
+
+      String getFullyQualifiedName(LogRecord event)
+      {
+         return event.getLoggerName();
+      }
+   }
+
+}
+




More information about the jboss-cvs-commits mailing list