bloritsch 00/11/17 12:28:35
Modified: src/org/apache/cocoon/servlet Tag: xml-cocoon2
CocoonServlet.java
Log:
Changed default log target to go to the context/WEB-INF/logs/cocoon.log
location. Also added a log target that logs the processing time for the page
by URL.
Revision Changes Path
No revision
No revision
1.1.4.31 +37 -22
xml-cocoon/src/org/apache/cocoon/servlet/Attic/CocoonServlet.java
Index: CocoonServlet.java
===================================================================
RCS file:
/home/cvs/xml-cocoon/src/org/apache/cocoon/servlet/Attic/CocoonServlet.java,v
retrieving revision 1.1.4.30
retrieving revision 1.1.4.31
diff -u -r1.1.4.30 -r1.1.4.31
--- CocoonServlet.java 2000/11/15 19:29:41 1.1.4.30
+++ CocoonServlet.java 2000/11/17 20:28:34 1.1.4.31
@@ -38,6 +38,11 @@
import org.apache.log.Logger;
import org.apache.log.LogKit;
import org.apache.log.Priority;
+import org.apache.log.Category;
+import org.apache.log.output.FileOutputLogTarget;
+import org.apache.log.LogTarget;
+import org.apache.log.filter.AbstractFilterTarget;
+import org.apache.log.LogEntry;
/**
@@ -47,7 +52,7 @@
* (Apache Software Foundation, Exoffice Technologies)
* @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Nicola Ken Barozzi</a> Aisa
- * @version CVS $Revision: 1.1.4.30 $ $Date: 2000/11/15 19:29:41 $
+ * @version CVS $Revision: 1.1.4.31 $ $Date: 2000/11/17 20:28:34 $
*/
public class CocoonServlet extends HttpServlet {
@@ -71,18 +76,21 @@
*/
public void init(ServletConfig conf) throws ServletException {
+ super.init(conf);
+
+ this.context = conf.getServletContext();
+
try {
- log = LogKit.createLogger("cocoon", new
URL("file://./logs/cocoon.log"), Priority.DEBUG);
- } catch (MalformedURLException mue) {
- LogKit.log("Could not set up Cocoon Logger, will use screen
instead", mue);
+ String path = "file://" +
+ this.context.getRealPath("/") +
+ "/WEB-INF/logs/cocoon.log";
+ log = LogKit.createLogger("cocoon", path, "DEBUG");
+ } catch (Exception e) {
+ LogKit.log("Could not set up Cocoon Logger, will use screen
instead", e);
}
LogKit.setGlobalPriority(Priority.DEBUG);
- super.init(conf);
-
- this.context = conf.getServletContext();
-
// WARNING (SM): the line below BREAKS the Servlet API portability of
// web applications.
// This is a hack to go around java compiler design problems that
@@ -236,11 +244,18 @@
ServletOutputStream out = res.getOutputStream();
long end = System.currentTimeMillis();
+ String timeString = processTime(end - start);
+ log.debug("'" + uri + "' " + timeString);
String showTime = req.getParameter(Cocoon.SHOWTIME_PARAM);
if ((showTime != null) && !showTime.equalsIgnoreCase("no")) {
- showTime(out, showTime.equalsIgnoreCase("hide"), end - start);
+ boolean hide = showTime.equalsIgnoreCase("hide");
+ out.print((hide) ? "<!-- " : "<p>");
+
+ out.print(timeString);
+
+ out.println((hide) ? " -->" : "</p>");
}
out.flush();
@@ -260,28 +275,28 @@
return null;
}
}
-
- private void showTime(ServletOutputStream out, boolean hide, long time)
throws IOException {
- out.print((hide) ? "<!-- " : "<p>");
+ private String processTime(long time) throws IOException {
- out.print("Processed by " + Cocoon.COMPLETE_NAME + " in ");
+ StringBuffer out = new StringBuffer("Processed by ")
+ .append(Cocoon.COMPLETE_NAME)
+ .append(" in ");
if (time > hour) {
- out.print(time / hour);
- out.print(" hours.");
+ out.append((float) time / (float) hour);
+ out.append(" hours.");
} else if (time > minute) {
- out.print(time / minute);
- out.print(" minutes.");
+ out.append((float) time / (float) minute);
+ out.append(" minutes.");
} else if (time > second) {
- out.print(time / second);
- out.print(" seconds.");
+ out.append((float) time / (float) second);
+ out.append(" seconds.");
} else {
- out.print(time);
- out.print(" milliseconds.");
+ out.append(time);
+ out.append(" milliseconds.");
}
- out.println((hide) ? " -->" : "</p>");
+ return out.toString();
}
}