<param name="DatePattern" value="'.'yyyy-MM-dd"/>
<param name="File" value="${jboss.server.log.dir}/collectionspace-perf.log"/>
<layout class="org.apache.log4j.PatternLayout">
- <!-- FIXME: Temporary change to accommodate interleaved CSV log entries -->
+ <!-- Change to accommodate interleaved CSV log entries -->
<!-- param name="ConversionPattern" value="%d [%t] %m%n"/ -->
<param name="ConversionPattern" value=""%d",%m%n"/>
</layout>
</filter>
<filter class="org.apache.log4j.varia.DenyAllFilter"></filter-->
</appender>
-
- <!-- collectionspace performance appender, generating a comma-separated value (CSV) -->
- <!-- format common to (at least) the services and app layers -->
- <appender name="CSLOG_PERF_CSV" class="org.jboss.logging.appender.DailyRollingFileAppender">
- <errorHandler class="org.jboss.logging.util.OnlyOnceErrorHandler"/>
- <param name="Append" value="false"/>
- <param name="DatePattern" value="'.'yyyy-MM-dd"/> <!-- Roll over at midnight daily -->
- <param name="File" value="${jboss.server.log.dir}/collectionspace-perf-csv.log"/>
- <layout class="org.apache.log4j.PatternLayout">
- <!-- param name="ConversionPattern" value=""%d",%r,%t,app,svc,%C{2},%M,method_get_uri_placeholder,svc%n"/ -->
- <param name="ConversionPattern" value=""%d",%m%n"/>
- </layout>
- </appender>
<!-- ================ -->
<!-- Limit categories -->
<priority value="DEBUG" />
<appender-ref ref="CSLOG_PERF"/>
</category>
-
- <category name="perf.collectionspace.csv">
- <priority value="DEBUG" />
- <appender-ref ref="CSLOG_PERF_CSV"/>
- </category>
<!-- ======================= -->
<!-- Setup the Root category -->
FilterConfig filterConfig = null;\r
\r
private final String CLASS_NAME = this.getClass().getSimpleName();\r
- private Logger csvPerfLogger = LoggerFactory.getLogger("perf.collectionspace.csv");\r
\r
/* (non-Javadoc)\r
* @see javax.servlet.Filter#destroy()\r
uri.append(':');\r
uri.append(httpRequest.getMethod());\r
Profiler profiler = new Profiler(uri.toString(), 0);\r
+ Profiler csvProfiler = new Profiler("org.collectionspace.perf.csv");\r
\r
// Start timing.\r
profiler.start();\r
\r
+ // Write a CSV-delimited message to the performance log,\r
+ // in a format intended to be interoperable with those\r
+ // generated by other system layers.\r
+ String csvMsg =\r
+ profiler.getStartTime()\r
+ + "," + profiler.getElapsedTime()\r
+ + "," + "request"\r
+ + "," + "app"\r
+ + "," + "svc"\r
+ + "," + httpRequest.getMethod()\r
+ + "," + ServletTools.getURL(httpRequest)\r
+ + "," + CLASS_NAME\r
+ + "," + Thread.currentThread().getName();\r
+ final boolean FORMAT_LOG_MESSAGE = false;\r
+ profiler.log(csvMsg, FORMAT_LOG_MESSAGE);\r
+\r
// Process the request.\r
chain.doFilter(request, response);\r
\r
// Stop timing and log performance-related metrics.\r
profiler.stop();\r
\r
- String csvMsg =\r
- "," + System.currentTimeMillis()\r
- + "," + Thread.currentThread().getName()\r
- + "," + "app"\r
+ csvMsg =\r
+ profiler.getStopTime()\r
+ + "," + profiler.getElapsedTime()\r
+ + "," + "response"\r
+ "," + "svc"\r
- + "," + CLASS_NAME\r
+ + "," + "app"\r
+ "," + httpRequest.getMethod()\r
+ "," + ServletTools.getURL(httpRequest)\r
- + "," + profiler.getElapsedTime();\r
+ + "," + CLASS_NAME\r
+ + "," + Thread.currentThread().getName();\r
+ profiler.log(csvMsg, FORMAT_LOG_MESSAGE);\r
\r
- // FIXME: Expedient change interleaves CSV-style log entries with entries\r
- // in the original perf log. These should be written to their own log file,\r
- // with their own patternLayout.\r
- profiler.log(csvMsg);\r
profiler.reset();\r
- // csvPerfLogger.debug(csvMsg);\r
}\r
}\r
\r
}\r
\r
/**\r
- * Writes a log entry.\r
+ * Writes a message to a log entry. The message will\r
+ * be formatted, using current settings for indentation,\r
+ * prefix, etc. before being written.\r
*\r
- * @param msg the message to log.\r
+ * @param msg the message to be written to a log entry.\r
*/\r
public void log(String msg) {\r
if (getLogger().isDebugEnabled()) {\r
}\r
}\r
\r
+ /**\r
+ * Writes a message to a log entry,\r
+ *\r
+ * @param msg the message to write to a log entry.\r
+ * @param formatMsg true if the message is to be formatted;\r
+ * false if it is not to be formatted.\r
+ */\r
+ public void log(String msg, boolean formatMsg) {\r
+ if (getLogger().isDebugEnabled()) {\r
+ if (formatMsg) {\r
+ getLogger().debug(formatLogMessage(msg));\r
+ } else {\r
+ getLogger().debug(msg);\r
+ }\r
+ }\r
+ }\r
+\r
/**\r
* Gets the logger.\r
*\r
protected Logger getLogger() {\r
return this.profileLogger;\r
}\r
-\r
+ \r
private void setMessagePrefix(String prefix) {\r
this.messagePrefix = prefix;\r
}\r
}\r
\r
/**\r
- * Returns a formatted log message, including indentation and prefix.\r
+ * Returns a formatted log message, after adding indentation and prefix, if any.\r
*\r
* @param msg the message to log.\r
- * @return a constructed log message, including indentation and prefix, if any.\r
+ * @return a formatted log message, including indentation and prefix, if any.\r
*/\r
private String formatLogMessage(String msg) {\r
StringBuffer logMsg = new StringBuffer();\r
}\r
return defaultStopMessage.toString();\r
}\r
+\r
}\r