[logback-dev] svn commit: r2172 - in logback/trunk: logback-classic/src/main/java/ch/qos/logback/classic/pattern logback-classic/src/test/java/ch/qos/logback/classic/pattern logback-core/src/main/java/ch/qos/logback/core
noreply.ceki at qos.ch
noreply.ceki at qos.ch
Fri Feb 27 14:54:13 CET 2009
Author: ceki
Date: Fri Feb 27 14:54:13 2009
New Revision: 2172
Modified:
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/TargetLengthBasedClassNameAbbreviator.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/pattern/ConverterTest.java
logback/trunk/logback-core/src/main/java/ch/qos/logback/core/CoreConstants.java
Log:
When the class name contains 13 or more segments (12 dots), the
abbreviation algorithm would bomb out with an exception. This was
reported by Lukas Zapletal in LBCLASSIC-110 and on the logback mailing
list.
The critical change is
int[] lengthArray = new int[ClassicConstants.MAX_DOTS];
instead of
int[] lengthArray = new int[ClassicConstants.MAX_DOTS+1];
The current MAX_DOTS limit has been increased from 12 to 16. However,
the with aforementioned "critical" change, the code can deal with any
number of dots as attested by the accompanying test case.
Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/TargetLengthBasedClassNameAbbreviator.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/TargetLengthBasedClassNameAbbreviator.java (original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/TargetLengthBasedClassNameAbbreviator.java Fri Feb 27 14:54:13 2009
@@ -1,21 +1,21 @@
/**
- * LOGBack: the reliable, fast and flexible logging library for Java.
- *
- * Copyright (C) 1999-2006, QOS.ch
- *
- * This library is free software, you can redistribute it and/or
- * modify it under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation.
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ *
+ * Copyright (C) 2000-2009, QOS.ch
+ *
+ * This library is free software, you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser General Public License as published by the Free
+ * Software Foundation.
*/
package ch.qos.logback.classic.pattern;
+import ch.qos.logback.classic.ClassicConstants;
import ch.qos.logback.core.CoreConstants;
public class TargetLengthBasedClassNameAbbreviator implements Abbreviator {
static private final int BUF_LIMIT = 256;
- static private final int MAX_DOTS = 12;
-
+
final int targetLength;
StringBuffer buf;
@@ -39,8 +39,8 @@
}
buf.setLength(0);
- int[] dotArray = new int[MAX_DOTS];
- int[] lengthArray = new int[MAX_DOTS];
+ int[] dotArray = new int[ClassicConstants.MAX_DOTS];
+ int[] lengthArray = new int[ClassicConstants.MAX_DOTS+1];
int dotCount = computeIndexes(fqClassName, dotArray);
@@ -72,7 +72,7 @@
int k = 0;
while (true) {
k = className.indexOf(CoreConstants.DOT, k);
- if (k != -1 && dotCount < MAX_DOTS) {
+ if (k != -1 && dotCount < ClassicConstants.MAX_DOTS) {
dotArray[dotCount] = k;
dotCount++;
k++;
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/pattern/ConverterTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/pattern/ConverterTest.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/pattern/ConverterTest.java Fri Feb 27 14:54:13 2009
@@ -1,7 +1,7 @@
/**
- * LOGBack: the reliable, fast and flexible logging library for Java.
+ * Logback: the generic, reliable, fast and flexible logging framework.
*
- * Copyright (C) 1999-2005, QOS.ch
+ * Copyright (C) 2000-2009, QOS.ch
*
* This library is free software, you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by the Free
@@ -21,6 +21,7 @@
import org.slf4j.MDC;
import org.slf4j.MarkerFactory;
+import ch.qos.logback.classic.ClassicConstants;
import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.LoggerContext;
@@ -36,7 +37,7 @@
LoggerContext lc = new LoggerContext();
Logger logger = lc.getLogger(ConverterTest.class);
- ILoggingEvent le;
+ LoggingEvent le;
List<String> optionList = new ArrayList<String>();
// The LoggingEvent is massaged with an FCQN of FormattingConverter. This
@@ -69,7 +70,7 @@
StringBuffer buf = new StringBuffer();
converter.write(buf, le);
// the number below should be the line number of the previous line
- assertEquals("70", buf.toString());
+ assertEquals("71", buf.toString());
}
}
@@ -164,6 +165,38 @@
}
@Test
+ public void testVeryLongLoggerName() {
+ ClassicConverter converter = new LoggerConverter();
+ this.optionList.add("5");
+ converter.setOptionList(this.optionList);
+ converter.start();
+ StringBuffer buf = new StringBuffer();
+
+ char c = 'a';
+ int extraParts = 3;
+ int totalParts = ClassicConstants.MAX_DOTS + extraParts;
+ StringBuilder loggerNameBuf = new StringBuilder();
+ StringBuilder witness = new StringBuilder();
+
+ for(int i = 0; i < totalParts ; i++) {
+ loggerNameBuf.append(c).append(c).append(c);
+ if(i < ClassicConstants.MAX_DOTS) {
+ witness.append(c);
+ } else {
+ witness.append(c).append(c).append(c);
+ }
+ loggerNameBuf.append('.');
+ witness.append('.');
+ }
+ loggerNameBuf.append("zzzzzz");
+ witness.append("zzzzzz");
+
+ le.setLoggerName(loggerNameBuf.toString());
+ converter.write(buf, le);
+ assertEquals(witness.toString(), buf.toString());
+ }
+
+ @Test
public void testClass() {
DynamicConverter<ILoggingEvent> converter = new ClassOfCallerConverter();
StringBuffer buf = new StringBuffer();
Modified: logback/trunk/logback-core/src/main/java/ch/qos/logback/core/CoreConstants.java
==============================================================================
--- logback/trunk/logback-core/src/main/java/ch/qos/logback/core/CoreConstants.java (original)
+++ logback/trunk/logback-core/src/main/java/ch/qos/logback/core/CoreConstants.java Fri Feb 27 14:54:13 2009
@@ -69,7 +69,7 @@
public static final int TABLE_ROW_LIMIT = 10000;
- // reset the ObjectOutputStream every 70 calls
+ // reset the ObjectOutputStream every OOS_RESET_FREQUENCY calls
// this avoid serious memory leaks
public static final int OOS_RESET_FREQUENCY = 70;
More information about the logback-dev
mailing list