1 18 19 package org.apache.jmeter.functions; 20 21 import java.io.Serializable ; 22 import java.util.Collection ; 23 import java.util.LinkedList ; 24 import java.util.List ; 25 26 import org.apache.jmeter.engine.util.CompoundVariable; 27 import org.apache.jmeter.samplers.SampleResult; 28 import org.apache.jmeter.samplers.Sampler; 29 import org.apache.jorphan.logging.LoggingManager; 30 import org.apache.log.Logger; 31 32 45 public class LogFunction2 extends AbstractFunction implements Serializable 46 { 47 private static Logger log = LoggingManager.getLoggerForClass(); 48 49 private static final List desc = new LinkedList (); 50 private static final String KEY = "__logn"; 51 52 private static final int MIN_PARAMETER_COUNT = 1; 54 private static final int MAX_PARAMETER_COUNT = 3; 55 static { 56 desc.add("String to be logged"); 57 desc.add("Log level (default INFO)"); 58 desc.add("Throwable text (optional)"); 59 } 60 private static final String DEFAULT_PRIORITY = "INFO"; 62 private Object [] values; 63 64 public LogFunction2() 65 { 66 } 67 68 public Object clone() 69 { 70 return new LogFunction2(); 71 } 72 73 public synchronized String execute( 74 SampleResult previousResult, 75 Sampler currentSampler) 76 throws InvalidVariableException 77 { 78 String stringToLog = ((CompoundVariable) values[0]).execute(); 79 80 String priorityString; 81 if (values.length > 1){ priorityString= ((CompoundVariable) values[1]).execute(); 83 if (priorityString.length()==0) priorityString= DEFAULT_PRIORITY; 84 } else { 85 priorityString = DEFAULT_PRIORITY; 86 } 87 88 Throwable t=null; 89 if (values.length > 2){ t = new Throwable (((CompoundVariable) values[2]).execute()); 91 } 92 93 LogFunction.logDetails(log,stringToLog,priorityString,t); 94 95 return ""; 96 97 } 98 99 public void setParameters(Collection parameters) 100 throws InvalidVariableException 101 { 102 103 values = parameters.toArray(); 104 105 if ((values.length < MIN_PARAMETER_COUNT) 106 || (values.length > MAX_PARAMETER_COUNT)) 107 { 108 throw new InvalidVariableException( 109 "Parameter Count not between " 110 + MIN_PARAMETER_COUNT 111 + " & " 112 + MAX_PARAMETER_COUNT); 113 } 114 115 } 116 117 public String getReferenceKey() 118 { 119 return KEY; 120 } 121 122 public List getArgumentDesc() 123 { 124 return desc; 125 } 126 127 } | Popular Tags |