You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jmeter-dev@jakarta.apache.org by se...@apache.org on 2007/12/03 18:29:55 UTC
svn commit: r600613 - in /jakarta/jmeter/trunk:
src/functions/org/apache/jmeter/functions/LogFunction.java
src/functions/org/apache/jmeter/functions/LogFunction2.java
xdocs/changes.xml xdocs/usermanual/functions.xml
Author: sebb
Date: Mon Dec 3 09:29:54 2007
New Revision: 600613
URL: http://svn.apache.org/viewvc?rev=600613&view=rev
Log:
Add optional comment to __log() function
Modified:
jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/LogFunction.java
jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/LogFunction2.java
jakarta/jmeter/trunk/xdocs/changes.xml
jakarta/jmeter/trunk/xdocs/usermanual/functions.xml
Modified: jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/LogFunction.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/LogFunction.java?rev=600613&r1=600612&r2=600613&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/LogFunction.java (original)
+++ jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/LogFunction.java Mon Dec 3 09:29:54 2007
@@ -26,16 +26,25 @@
import org.apache.jmeter.engine.util.CompoundVariable;
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.samplers.Sampler;
+import org.apache.jmeter.util.JMeterUtils;
import org.apache.jorphan.logging.LoggingManager;
import org.apache.log.Logger;
import org.apache.log.Priority;
/**
- * Function to log a message
- *
- * Parameters: - string - log level (optional; defaults to INFO; or DEBUG if
- * unrecognised) - throwable message (optional)
+ * <p>
+ * Function to log a message.
+ * </p>
*
+ * <p>
+ * Parameters:
+ * <ul>
+ * <li>string value</li>
+ * <li>log level (optional; defaults to INFO; or DEBUG if unrecognised; or can use OUT or ERR)</li>
+ * <li>throwable message (optional)</li>
+ * <li>comment (optional)</li>
+ * </ul>
+ * </p>
* Returns: - the input string
*
*/
@@ -49,15 +58,18 @@
// Number of parameters expected - used to reject invalid calls
private static final int MIN_PARAMETER_COUNT = 1;
- private static final int MAX_PARAMETER_COUNT = 3;
+ private static final int MAX_PARAMETER_COUNT = 4;
static {
- desc.add("String to be logged");
- desc.add("Log level (default INFO)");
- desc.add("Throwable text (optional)");
+ desc.add(JMeterUtils.getResString("log_function_string_ret")); //$NON-NLS-1$
+ desc.add(JMeterUtils.getResString("log_function_level")); //$NON-NLS-1$
+ desc.add(JMeterUtils.getResString("log_function_throwable")); //$NON-NLS-1$
+ desc.add(JMeterUtils.getResString("log_function_comment")); //$NON-NLS-1$
}
private static final String DEFAULT_PRIORITY = "INFO"; //$NON-NLS-1$
+ private static final String DEFAULT_SEPARATOR = " : "; //$NON-NLS-1$
+
private Object[] values;
public LogFunction() {
@@ -82,41 +94,66 @@
Throwable t = null;
if (values.length > 2) { // Throwable wanted
- t = new Throwable(((CompoundVariable) values[2]).execute());
+ String value = ((CompoundVariable) values[2]).execute();
+ if (value.length() > 0) t = new Throwable(value);
}
- logDetails(log, stringToLog, priorityString, t);
+ String comment = "";
+ if (values.length > 3) { // Comment wanted
+ comment = ((CompoundVariable) values[3]).execute();
+ }
+
+ logDetails(log, stringToLog, priorityString, t, comment);
return stringToLog;
}
// Common output function
- private static void printDetails(java.io.PrintStream ps, String s, Throwable t) {
+ private static void printDetails(java.io.PrintStream ps, String s, Throwable t, String c) {
String tn = Thread.currentThread().getName();
+
+ StringBuffer sb = new StringBuffer(80);
+ sb.append("Log: ");
+ sb.append(tn);
+ if (c.length()>0){
+ sb.append(" ");
+ sb.append(c);
+ } else {
+ sb.append(DEFAULT_SEPARATOR);
+ }
if (t != null) {
- ps.print("Log: " + tn + " : " + s + " ");
+ sb.append(" ");
+ ps.print(sb.toString());
t.printStackTrace(ps);
} else {
- ps.println("Log: " + tn + " : " + s);
+ ps.print(sb.toString());
}
}
// Routine to perform the output (also used by __logn() function)
- static void logDetails(Logger l, String s, String prio, Throwable t) {
+ static void logDetails(Logger l, String s, String prio, Throwable t, String c) {
if (prio.equalsIgnoreCase("OUT")) //$NON-NLS-1
{
- printDetails(System.out, s, t);
+ printDetails(System.out, s, t, c);
} else if (prio.equalsIgnoreCase("ERR")) //$NON-NLS-1
{
- printDetails(System.err, s, t);
+ printDetails(System.err, s, t, c);
} else {
// N.B. if the string is not recognised, DEBUG is assumed
Priority p = Priority.getPriorityForName(prio);
- if (log.isPriorityEnabled(p)) {// Thread method is potentially
- // expensive
+ if (log.isPriorityEnabled(p)) {// Thread method is potentially expensive
String tn = Thread.currentThread().getName();
- log.log(p, tn + " " + s, t);
+ StringBuffer sb = new StringBuffer(40);
+ sb.append(tn);
+ if (c.length()>0){
+ sb.append(" ");
+ sb.append(c);
+ } else {
+ sb.append(DEFAULT_SEPARATOR);
+ }
+ sb.append(s);
+ log.log(p, sb.toString(), t);
}
}
Modified: jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/LogFunction2.java
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/LogFunction2.java?rev=600613&r1=600612&r2=600613&view=diff
==============================================================================
--- jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/LogFunction2.java (original)
+++ jakarta/jmeter/trunk/src/functions/org/apache/jmeter/functions/LogFunction2.java Mon Dec 3 09:29:54 2007
@@ -26,17 +26,24 @@
import org.apache.jmeter.engine.util.CompoundVariable;
import org.apache.jmeter.samplers.SampleResult;
import org.apache.jmeter.samplers.Sampler;
+import org.apache.jmeter.util.JMeterUtils;
import org.apache.jorphan.logging.LoggingManager;
import org.apache.log.Logger;
/**
- * Function to log a message
+ * <p>
+ * Function to log a message.
+ * </p>
*
- * Parameters: - string - log level (optional; defaults to INFO; or DEBUG if
- * unrecognised) - throwable message (optional)
- *
- * Returns: - Empty String (so can be used where return value would be a
- * nuisance)
+ * <p>
+ * Parameters:
+ * <ul>
+ * <li>string value</li>
+ * <li>log level (optional; defaults to INFO; or DEBUG if unrecognised; or can use OUT or ERR)</li>
+ * <li>throwable message (optional)</li>
+ * </ul>
+ * </p>
+ * Returns: - Empty String (so can be used where return value would be a nuisance)
*
*/
public class LogFunction2 extends AbstractFunction implements Serializable {
@@ -51,9 +58,9 @@
private static final int MAX_PARAMETER_COUNT = 3;
static {
- desc.add("String to be logged");
- desc.add("Log level (default INFO)");
- desc.add("Throwable text (optional)");
+ desc.add(JMeterUtils.getResString("log_function_string")); //$NON-NLS-1$
+ desc.add(JMeterUtils.getResString("log_function_level")); //$NON-NLS-1$
+ desc.add(JMeterUtils.getResString("log_function_throwable")); //$NON-NLS-1$
}
private static final String DEFAULT_PRIORITY = "INFO"; //$NON-NLS-1$
@@ -85,7 +92,7 @@
t = new Throwable(((CompoundVariable) values[2]).execute());
}
- LogFunction.logDetails(log, stringToLog, priorityString, t);
+ LogFunction.logDetails(log, stringToLog, priorityString, t, "");
return "";
Modified: jakarta/jmeter/trunk/xdocs/changes.xml
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/changes.xml?rev=600613&r1=600612&r2=600613&view=diff
==============================================================================
--- jakarta/jmeter/trunk/xdocs/changes.xml (original)
+++ jakarta/jmeter/trunk/xdocs/changes.xml Mon Dec 3 09:29:54 2007
@@ -49,6 +49,7 @@
<li>longSum() function added</li>
<li>Bug 43382 - configure Tidy output (warnings, errors) for XPath Assertion and Post-Processor</li>
<li>Bug 43984 - trim spaces from port field</li>
+<li>Add optional comment to __log() function</li>
</ul>
<h4>Non-functional changes</h4>
@@ -57,6 +58,7 @@
<li>Build process now detects missing 3rd party libraries and reports need for both binary and source archives</li>
<li>Skip BeanShell tests if jar is not present</li>
<li>Update to Xalan 2.7.1</li>
+<li>Use properties for log/logn function descriptions</li>
</ul>
<!-- =================== -->
Modified: jakarta/jmeter/trunk/xdocs/usermanual/functions.xml
URL: http://svn.apache.org/viewvc/jakarta/jmeter/trunk/xdocs/usermanual/functions.xml?rev=600613&r1=600612&r2=600613&view=diff
==============================================================================
--- jakarta/jmeter/trunk/xdocs/usermanual/functions.xml (original)
+++ jakarta/jmeter/trunk/xdocs/usermanual/functions.xml Mon Dec 3 09:29:54 2007
@@ -572,14 +572,17 @@
<property name="String to be logged" required="Yes">A string</property>
<property name="Log Level" required="No">OUT, ERR, DEBUG, INFO (default), WARN or ERROR</property>
<property name="Throwable text" required="No">If non-empty, creates a Throwable to pass to the logger</property>
+ <property name="Comment" required="No">If present, it is displayed in the string.
+ Useful for identifying what is being logged.</property>
</properties>
<p>The OUT and ERR log level names are used to direct the output to System.out and System.err respectively.
In this case, the output is always printed - it does not depend on the current log setting.
</p>
<pre>
For example:
- ${__log(Message)} - written to the log file
+ ${__log(Message)} - written to the log file as "...thread Name : Message"
${__log(Message,OUT)} - written to console window
+ ${__log(${VAR},,,VAR=)} - written to log file as "...thread Name VAR=value"
</pre>
</component>
---------------------------------------------------------------------
To unsubscribe, e-mail: jmeter-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jmeter-dev-help@jakarta.apache.org