You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@avalon.apache.org by le...@apache.org on 2002/04/07 07:09:45 UTC
cvs commit: jakarta-avalon-logkit/src/java/org/apache/log/format PatternFormatter.java
leif 02/04/06 21:09:45
Modified: src/java/org/apache/log/format PatternFormatter.java
Log:
Added support for logging the thread name.
Revision Changes Path
1.28 +20 -1 jakarta-avalon-logkit/src/java/org/apache/log/format/PatternFormatter.java
Index: PatternFormatter.java
===================================================================
RCS file: /home/cvs/jakarta-avalon-logkit/src/java/org/apache/log/format/PatternFormatter.java,v
retrieving revision 1.27
retrieving revision 1.28
diff -u -r1.27 -r1.28
--- PatternFormatter.java 27 Mar 2002 22:07:56 -0000 1.27
+++ PatternFormatter.java 7 Apr 2002 05:09:45 -0000 1.28
@@ -59,6 +59,9 @@
* </tr><tr>
* <td><b>priority</b></td>
* <td>Priority value of the logging event.</td>
+ * </tr><tr>
+ * <td><b>thread</b></td>
+ * <td>Name of the thread which logged the event.</td>
* </tr>
* </table>
* </p></li>
@@ -96,7 +99,8 @@
* </p>
* @author <a href="mailto:peter@apache.org">Peter Donald</a>
* @author <a href="mailto:sylvain@apache.org">Sylvain Wallez</a>
- * @version CVS $Revision: 1.27 $ $Date: 2002/03/27 22:07:56 $
+ * @author <a href="mailto:leif@tanukisoftware.com">Leif Mortenson</a>
+ * @version CVS $Revision: 1.28 $ $Date: 2002/04/07 05:09:45 $
*/
public class PatternFormatter
implements Formatter, org.apache.log.Formatter
@@ -109,6 +113,7 @@
private final static int TYPE_RELATIVE_TIME = 6;
private final static int TYPE_THROWABLE = 7;
private final static int TYPE_PRIORITY = 8;
+ private final static int TYPE_THREAD = 9;
/**
* The maximum value used for TYPEs. Subclasses can define their own TYPEs
@@ -123,6 +128,7 @@
private final static String TYPE_RELATIVE_TIME_STR = "rtime";
private final static String TYPE_THROWABLE_STR = "throwable";
private final static String TYPE_PRIORITY_STR = "priority";
+ private final static String TYPE_THREAD_STR = "thread";
private final static String SPACE_16 = " ";
private final static String SPACE_8 = " ";
@@ -465,6 +471,9 @@
{
return getContextMap( event.getContextMap(), run.m_format );
}
+
+ case TYPE_THREAD:
+ return getThread( run.m_format );
default:
throw new IllegalStateException( "Unknown Pattern specification." + run.m_type );
@@ -492,6 +501,14 @@
}
/**
+ * Get formatted thread string.
+ */
+ protected String getThread( final String format )
+ {
+ return Thread.currentThread().getName();
+ }
+
+ /**
* Utility method to format context.
*
* @param context the context string
@@ -616,6 +633,8 @@
return TYPE_TIME;
else if( type.equalsIgnoreCase( TYPE_RELATIVE_TIME_STR ) )
return TYPE_RELATIVE_TIME;
+ else if( type.equalsIgnoreCase( TYPE_THREAD_STR ) )
+ return TYPE_THREAD;
else if( type.equalsIgnoreCase( TYPE_THROWABLE_STR ) )
{
return TYPE_THROWABLE;
--
To unsubscribe, e-mail: <ma...@jakarta.apache.org>
For additional commands, e-mail: <ma...@jakarta.apache.org>