[logback-dev] svn commit: r2202 - logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/corpus
noreply.ceki at qos.ch
noreply.ceki at qos.ch
Tue Mar 10 15:14:22 CET 2009
Author: ceki
Date: Tue Mar 10 15:14:22 2009
New Revision: 2202
Modified:
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/corpus/Corpus.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/corpus/CorpusModel.java
Log:
- CorpusModel will optionally include caller data.
- The standard corpus now includes caller data.
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/corpus/Corpus.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/corpus/Corpus.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/corpus/Corpus.java Tue Mar 10 15:14:22 2009
@@ -14,6 +14,7 @@
import java.net.URL;
import java.util.List;
+import ch.qos.logback.classic.ClassicConstants;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.classic.spi.IThrowableProxy;
import ch.qos.logback.classic.spi.LoggerContextVO;
@@ -58,10 +59,11 @@
static public ILoggingEvent[] makeStandardCorpus() throws IOException {
List<String> worldList = getStandatdCorpusWordList();
CorpusModel corpusMaker = new CorpusModel(STANDARD_SEED, worldList);
- return make(corpusMaker, STANDARD_CORPUS_SIZE);
+ return make(corpusMaker, STANDARD_CORPUS_SIZE, true);
}
- static public ILoggingEvent[] make(CorpusModel corpusModel, int n) {
+ static public ILoggingEvent[] make(CorpusModel corpusModel, int n,
+ boolean withCallerData) {
LoggerContextVO lcVO = corpusModel.getRandomlyNamedLoggerContextVO();
PubLoggingEventVO[] plevoArray = new PubLoggingEventVO[n];
for (int i = 0; i < n; i++) {
@@ -76,7 +78,11 @@
e.message = logStatement.mat.message;
e.argumentArray = corpusModel
.getRandomArgumentArray(logStatement.mat.numberOfArguments);
- e.throwableProxy = logStatement.throwableProxy;
+
+ if (withCallerData) {
+ e.callerDataArray = corpusModel.getRandomCallerData(
+ ClassicConstants.DEFAULT_MAX_CALLEDER_DATA_DEPTH, e.loggerName);
+ }
e.threadName = corpusModel.getRandomThreadNameFromPool();
}
return plevoArray;
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/corpus/CorpusModel.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/corpus/CorpusModel.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/corpus/CorpusModel.java Tue Mar 10 15:14:22 2009
@@ -14,6 +14,7 @@
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.LoggerContext;
+import ch.qos.logback.classic.spi.CallerData;
import ch.qos.logback.classic.spi.ClassPackagingData;
import ch.qos.logback.classic.spi.LoggerContextVO;
import ch.qos.logback.classic.spi.StackTraceElementProxy;
@@ -84,6 +85,7 @@
final List<String> worldList;
String[] threadNamePool;
LogStatement[] logStatementPool;
+ String[] loggerNamePool;
// 2009-03-06 13:08 GMT
long lastTimeStamp = 1236344888578L;
@@ -92,6 +94,7 @@
random = new Random(seed);
this.worldList = worldList;
buildThreadNamePool();
+ buildLoggerNamePool();
buildLogStatementPool();
}
@@ -102,11 +105,14 @@
}
}
- private void buildLogStatementPool() {
- String[] loggerNamePool = new String[LOGGER_POOL_SIZE];
+ private void buildLoggerNamePool() {
+ loggerNamePool = new String[LOGGER_POOL_SIZE];
for (int i = 0; i < LOGGER_POOL_SIZE; i++) {
loggerNamePool[i] = makeRandomLoggerName();
}
+ }
+
+ private void buildLogStatementPool() {
logStatementPool = new LogStatement[LOG_STATEMENT_POOL_SIZE];
for (int i = 0; i < LOG_STATEMENT_POOL_SIZE; i++) {
logStatementPool[i] = makeRandomLogStatement(loggerNamePool);
@@ -169,6 +175,28 @@
return worldList.get(randomIndex);
}
+ String extractLastPart(String loggerName) {
+ int i = loggerName.lastIndexOf('.');
+ if (i == -1) {
+ return loggerName;
+ } else {
+ return loggerName.substring(i + 1);
+ }
+ }
+
+ public CallerData[] getRandomCallerData(int depth, String loggerName) {
+ CallerData[] cda = new CallerData[depth];
+ CallerData cd = new CallerData(extractLastPart(loggerName), loggerName,
+ getRandomJavaIdentifier(), 10);
+ cda[0] = cd;
+ for (int i = 1; i < depth; i++) {
+ String ln = getRandomLoggerNameFromPool(loggerNamePool);
+ cda[i] = new CallerData(extractLastPart(ln), ln,
+ getRandomJavaIdentifier(), i * 10);
+ }
+ return cda;
+ }
+
public Object[] getRandomArgumentArray(int numOfArguments) {
if (numOfArguments == 0) {
return null;
More information about the logback-dev
mailing list