cziegeler 01/08/12 22:57:56
Modified: src/org/apache/cocoon/util/log Tag: cocoon_20_branch
CocoonLogFormatter.java XMLCocoonLogFormatter.java
Log:
Applied a very small patch to change the recently added date in the logs to a
compacter format.
Submitted by: Stuart Roebuck ([EMAIL PROTECTED])
Revision Changes Path
No revision
No revision
1.3.2.2 +28 -26
xml-cocoon2/src/org/apache/cocoon/util/log/CocoonLogFormatter.java
Index: CocoonLogFormatter.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/org/apache/cocoon/util/log/CocoonLogFormatter.java,v
retrieving revision 1.3.2.1
retrieving revision 1.3.2.2
diff -u -r1.3.2.1 -r1.3.2.2
--- CocoonLogFormatter.java 2001/08/08 09:55:41 1.3.2.1
+++ CocoonLogFormatter.java 2001/08/13 05:57:56 1.3.2.2
@@ -8,6 +8,7 @@
package org.apache.cocoon.util.log;
+import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;
@@ -33,7 +34,7 @@
* </ul>
*
* @author <a href="mailto:[EMAIL PROTECTED]">Sylvain Wallez</a>
- * @version CVS $Revision: 1.3.2.1 $ $Date: 2001/08/08 09:55:41 $
+ * @version CVS $Revision: 1.3.2.2 $ $Date: 2001/08/13 05:57:56 $
*/
public class CocoonLogFormatter extends ExtensiblePatternFormatter
@@ -41,15 +42,16 @@
protected final static int TYPE_CLASS = MAX_TYPE + 1;
protected final static int TYPE_URI = MAX_TYPE + 2;
protected final static int TYPE_THREAD = MAX_TYPE + 3;
-
+
protected final static String TYPE_CLASS_STR = "class";
protected final static String TYPE_CLASS_SHORT_STR = "short";
protected final static String TYPE_URI_STR = "uri";
protected final static String TYPE_THREAD_STR = "thread";
-
-
- /**
+
+ protected final SimpleDateFormat dateFormatter = new
SimpleDateFormat("(yyyy-MM-dd) HH:mm.ss:SSS");
+
+ /**
* Hack to get the call stack as an array of classes. The
* SecurityManager class provides it as a protected method, so
* change it to public through a new method !
@@ -72,12 +74,12 @@
/** The class that we will search for in the call stack */
private Class loggerClass = org.apache.log.Logger.class;
-
+
private CallStack callStack = new CallStack();
-
+
protected int getTypeIdFor(String type) {
-
+
// Search for new patterns defined here, or else delegate
// to the parent class
if (type.equalsIgnoreCase(TYPE_CLASS_STR))
@@ -97,31 +99,31 @@
switch (run.m_type) {
case TYPE_CLASS :
return getClass(run.m_format);
-
+
case TYPE_URI :
return getURI(event.getContextStack());
-
+
case TYPE_THREAD :
return getThread(event.getContextStack());
}
-
+
return super.formatPatternRun(event, run);
}
-
+
/**
* Finds the class that has called Logger.
*/
private String getClass(String format) {
-
+
Class[] stack = this.callStack.get();
-
+
// Traverse the call stack in reverse order until we find a Logger
for (int i = stack.length-1; i >= 0; i--) {
if (this.loggerClass.isAssignableFrom(stack[i])) {
-
+
// Found : the caller is the previous stack element
String className = stack[i+1].getName();
-
+
// Handle optional format
if (TYPE_CLASS_SHORT_STR.equalsIgnoreCase(format))
{
@@ -129,23 +131,23 @@
if (pos >= 0)
className = className.substring(pos + 1);
}
-
+
return className;
}
}
-
+
// No Logger found in call stack : can occur with AsyncLogTarget
// where formatting takes place in a different thread.
return "Unknown-class";
}
-
+
/**
* Find the URI that is being processed.
*/
-
+
private String getURI(ContextStack ctxStack) {
String result = "Unknown-URI";
-
+
// Get URI from the first context stack element, if it's a Map (the object
model).
if (ctxStack.getSize() > 1) {
Object context = ctxStack.get(1);
@@ -157,21 +159,21 @@
}
}
}
-
+
return result;
}
-
+
/**
* Find the thread that is logged this event.
*/
-
+
private String getThread(ContextStack ctxStack) {
if (ctxStack.getSize() > 0)
return String.valueOf(ctxStack.get(0));
else
return "Unknown-thread";
}
-
+
/**
* Utility method to format stack trace so that CascadingExceptions are
* formatted with all nested exceptions.
@@ -207,7 +209,7 @@
*/
protected String getTime( final long time, final String format )
{
- return new Date().toString();
+ return this.dateFormatter.format(new Date());
}
}
1.1.2.3 +2 -2
xml-cocoon2/src/org/apache/cocoon/util/log/XMLCocoonLogFormatter.java
Index: XMLCocoonLogFormatter.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/org/apache/cocoon/util/log/XMLCocoonLogFormatter.java,v
retrieving revision 1.1.2.2
retrieving revision 1.1.2.3
diff -u -r1.1.2.2 -r1.1.2.3
--- XMLCocoonLogFormatter.java 2001/08/09 12:38:44 1.1.2.2
+++ XMLCocoonLogFormatter.java 2001/08/13 05:57:56 1.1.2.3
@@ -49,7 +49,7 @@
* @author <a href="mailto:[EMAIL PROTECTED]">Peter Donald</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Sylvain Wallez</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Carsten Ziegeler</a>
- * @version CVS $Revision: 1.1.2.2 $ $Date: 2001/08/09 12:38:44 $
+ * @version CVS $Revision: 1.1.2.3 $ $Date: 2001/08/13 05:57:56 $
*/
public class XMLCocoonLogFormatter
implements Formatter {
@@ -82,7 +82,7 @@
"thread"}; // 10
protected final static String EOL = System.getProperty("line.separator", "\n");
- protected final SimpleDateFormat dateFormatter = new SimpleDateFormat();
+ protected final SimpleDateFormat dateFormatter = new
SimpleDateFormat("(yyyy-MM-dd) HH:mm.ss:SSS");
protected int[] types;
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]