[logback-dev] svn commit: r1967 - in logback/trunk: logback-classic/src/main/java/ch/qos/logback/classic/pattern logback-classic/src/test/java/ch/qos/logback/classic/pattern logback-site/src/site/pages logback-site/src/site/pages/css logback-site/src/site/pages/manual
noreply.ceki at qos.ch
noreply.ceki at qos.ch
Wed Nov 12 19:40:35 CET 2008
Author: ceki
Date: Wed Nov 12 19:40:35 2008
New Revision: 1967
Added:
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/ClassNameOnlyAbbreviator.java
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/TargetLengthBasedClassNameAbbreviator.java
- copied, changed from r1899, /logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/ClassNameAbbreviator.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/pattern/TargetLengthBasedClassNameAbbreviatorTest.java
- copied, changed from r1899, /logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/pattern/ClassNameAbbreviatorTest.java
Removed:
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/ClassNameAbbreviator.java
logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/pattern/ClassNameAbbreviatorTest.java
Modified:
logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/NamedConverter.java
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/PackageTest.java
logback/trunk/logback-site/src/site/pages/css/common.css
logback/trunk/logback-site/src/site/pages/manual/layouts.html
logback/trunk/logback-site/src/site/pages/news.html
Log:
The logger and class name converters now consider zero as
having special meaning, and will return the simple class name,
removing the package name prefix. This feature was asked by
Silvano Maffeis.
Added: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/ClassNameOnlyAbbreviator.java
==============================================================================
--- (empty file)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/ClassNameOnlyAbbreviator.java Wed Nov 12 19:40:35 2008
@@ -0,0 +1,30 @@
+/**
+ * Logback: the generic, reliable, fast and flexible logging framework.
+ *
+ * Copyright (C) 2000-2008, 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.ClassicGlobal;
+
+/**
+ * This abbreviator returns the class name from a fully qualified class name,
+ * removing the leading package name.
+ *
+ * @author Ceki Gülcü
+ */
+public class ClassNameOnlyAbbreviator implements Abbreviator {
+
+ public String abbreviate(String fqClassName) {
+ int lastIndex = fqClassName.lastIndexOf(ClassicGlobal.DOT);
+ if (lastIndex != -1) {
+ return fqClassName.substring(lastIndex + 1, fqClassName.length());
+ } else {
+ return fqClassName;
+ }
+ }
+}
Modified: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/NamedConverter.java
==============================================================================
--- logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/NamedConverter.java (original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/NamedConverter.java Wed Nov 12 19:40:35 2008
@@ -29,8 +29,10 @@
if (optStr != null) {
try {
int targetLen = Integer.parseInt(optStr);
- if (targetLen > 0) {
- abbreviator = new ClassNameAbbreviator(targetLen);
+ if (targetLen == 0) {
+ abbreviator = new ClassNameOnlyAbbreviator();
+ } else if (targetLen > 0) {
+ abbreviator = new TargetLengthBasedClassNameAbbreviator(targetLen);
}
} catch (NumberFormatException nfe) {
// FIXME: better error reporting
Copied: logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/TargetLengthBasedClassNameAbbreviator.java (from r1899, /logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/ClassNameAbbreviator.java)
==============================================================================
--- /logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/ClassNameAbbreviator.java (original)
+++ logback/trunk/logback-classic/src/main/java/ch/qos/logback/classic/pattern/TargetLengthBasedClassNameAbbreviator.java Wed Nov 12 19:40:35 2008
@@ -11,7 +11,7 @@
import ch.qos.logback.classic.ClassicGlobal;
-public class ClassNameAbbreviator implements Abbreviator {
+public class TargetLengthBasedClassNameAbbreviator implements Abbreviator {
static private final int BUF_LIMIT = 256;
static private final int MAX_DOTS = 12;
@@ -19,19 +19,19 @@
final int targetLength;
StringBuffer buf;
- public ClassNameAbbreviator(int targetLength) {
+ public TargetLengthBasedClassNameAbbreviator(int targetLength) {
this.targetLength = targetLength;
buf = new StringBuffer(targetLength);
}
- public String abbreviate(String className) {
- if (className == null) {
+ public String abbreviate(String fqClassName) {
+ if (fqClassName == null) {
throw new IllegalArgumentException("Class name may not be null");
}
- int inLen = className.length();
+ int inLen = fqClassName.length();
if (inLen < targetLength) {
- return className;
+ return fqClassName;
}
if (buf.capacity() > BUF_LIMIT) {
@@ -42,30 +42,31 @@
int[] dotArray = new int[MAX_DOTS];
int[] lengthArray = new int[MAX_DOTS];
- int dotCount = computeIndexes(className, dotArray);
+ int dotCount = computeIndexes(fqClassName, dotArray);
- //System.out.println();
- //System.out.println("Dot count for [" + className + "] is " + dotCount);
+ // System.out.println();
+ // System.out.println("Dot count for [" + className + "] is " + dotCount);
// if there are not dots than abbreviation is not possible
if (dotCount == 0) {
- return className;
+ return fqClassName;
}
- //printArray("dotArray: ", dotArray);
- computeLengthArray(className, dotArray, lengthArray, dotCount);
- //printArray("lengthArray: ", lengthArray);
+ // printArray("dotArray: ", dotArray);
+ computeLengthArray(fqClassName, dotArray, lengthArray, dotCount);
+ // printArray("lengthArray: ", lengthArray);
for (int i = 0; i <= dotCount; i++) {
if (i == 0) {
- buf.append(className.substring(0, lengthArray[i] - 1));
+ buf.append(fqClassName.substring(0, lengthArray[i] - 1));
} else {
- buf.append(className.substring(dotArray[i - 1], dotArray[i - 1]
+ buf.append(fqClassName.substring(dotArray[i - 1], dotArray[i - 1]
+ lengthArray[i]));
}
- //System.out.println("i=" + i + ", buf=" + buf);
+ // System.out.println("i=" + i + ", buf=" + buf);
}
return buf.toString();
}
+
static int computeIndexes(final String className, int[] dotArray) {
int dotCount = 0;
int k = 0;
@@ -85,9 +86,9 @@
void computeLengthArray(final String className, int[] dotArray,
int[] lengthArray, int dotCount) {
int toTrim = className.length() - targetLength;
- //System.out.println("toTrim=" + toTrim);
-
- //int toTrimAvarage = 0;
+ // System.out.println("toTrim=" + toTrim);
+
+ // int toTrimAvarage = 0;
int len;
for (int i = 0; i < dotCount; i++) {
@@ -99,7 +100,7 @@
// System.out.println("i=" + i + ", available = " + available);
len = (available < 1) ? available : 1;
- //System.out.println("i=" + i + ", toTrim = " + toTrim);
+ // System.out.println("i=" + i + ", toTrim = " + toTrim);
if (toTrim > 0) {
len = (available < 1) ? available : 1;
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 Wed Nov 12 19:40:35 2008
@@ -9,11 +9,13 @@
*/
package ch.qos.logback.classic.pattern;
+import static org.junit.Assert.*;
+
import java.util.ArrayList;
import java.util.List;
-import junit.framework.TestCase;
-
+import org.junit.Before;
+import org.junit.Test;
import org.slf4j.MDC;
import org.slf4j.MarkerFactory;
@@ -27,29 +29,16 @@
import ch.qos.logback.core.pattern.DynamicConverter;
import ch.qos.logback.core.pattern.FormatInfo;
-public class ConverterTest extends TestCase {
+public class ConverterTest {
LoggerContext lc = new LoggerContext();
Logger logger = lc.getLogger(ConverterTest.class);
LoggingEvent le;
List<String> optionList = new ArrayList<String>();
- public ConverterTest(String arg0) {
- super(arg0);
-
- Exception rootEx = getException("Innermost", null);
- Exception nestedEx = getException("Nested", rootEx);
-
- Exception ex = new Exception("Bogus exception", nestedEx);
-
- le = makeLoggingEvent(ex);
- // ex.printStackTrace();
- }
-
// The LoggingEvent is massaged with an FCQN of FormattingConverter. This
- // forces the
- // returned caller information to match the caller stack for this this
- // particular test.
+ // forces the returned caller information to match the caller stack for this
+ // this particular test.
LoggingEvent makeLoggingEvent(Exception ex) {
return new LoggingEvent(
ch.qos.logback.core.pattern.FormattingConverter.class.getName(),
@@ -60,24 +49,28 @@
return new Exception(msg, cause);
}
- protected void setUp() throws Exception {
- super.setUp();
- }
+ @Before
+ public void setUp() throws Exception {
+ Exception rootEx = getException("Innermost", null);
+ Exception nestedEx = getException("Nested", rootEx);
- protected void tearDown() throws Exception {
- super.tearDown();
+ Exception ex = new Exception("Bogus exception", nestedEx);
+
+ le = makeLoggingEvent(ex);
}
+ @Test
public void testLineOfCaller() {
{
DynamicConverter<LoggingEvent> converter = new LineOfCallerConverter();
StringBuffer buf = new StringBuffer();
converter.write(buf, le);
// the number below should be the line number of the previous line
- assertEquals("75", buf.toString());
+ assertEquals("67", buf.toString());
}
}
+ @Test
public void testLevel() {
{
DynamicConverter<LoggingEvent> converter = new LevelConverter();
@@ -94,6 +87,7 @@
}
}
+ @Test
public void testThread() {
DynamicConverter<LoggingEvent> converter = new ThreadConverter();
StringBuffer buf = new StringBuffer();
@@ -102,6 +96,7 @@
assertTrue(buf.toString().matches(regex));
}
+ @Test
public void testMessage() {
DynamicConverter<LoggingEvent> converter = new MessageConverter();
StringBuffer buf = new StringBuffer();
@@ -109,6 +104,7 @@
assertEquals("Some message", buf.toString());
}
+ @Test
public void testLineSeparator() {
DynamicConverter<LoggingEvent> converter = new LineSeparatorConverter();
StringBuffer buf = new StringBuffer();
@@ -116,12 +112,12 @@
assertEquals(CoreConstants.LINE_SEPARATOR, buf.toString());
}
+ @Test
public void testException() {
{
DynamicConverter<LoggingEvent> converter = new ThrowableProxyConverter();
StringBuffer buf = new StringBuffer();
converter.write(buf, le);
- // System.out.println(buf);
}
{
@@ -130,10 +126,10 @@
converter.setOptionList(this.optionList);
StringBuffer buf = new StringBuffer();
converter.write(buf, le);
- // System.out.println(buf);
}
}
+ @Test
public void testLogger() {
{
DynamicConverter<LoggingEvent> converter = new LoggerConverter();
@@ -151,35 +147,44 @@
converter.write(buf, le);
assertEquals("c.q.l.c.p.ConverterTest", buf.toString());
}
- }
- public void testClass() {
{
- DynamicConverter<LoggingEvent> converter = new ClassOfCallerConverter();
+ DynamicConverter<LoggingEvent> converter = new LoggerConverter();
+ this.optionList.clear();
+ this.optionList.add("0");
+ converter.setOptionList(this.optionList);
+ converter.start();
StringBuffer buf = new StringBuffer();
converter.write(buf, le);
- assertEquals(this.getClass().getName(), buf.toString());
+ assertEquals("ConverterTest", buf.toString());
}
}
+ @Test
+ public void testClass() {
+ DynamicConverter<LoggingEvent> converter = new ClassOfCallerConverter();
+ StringBuffer buf = new StringBuffer();
+ converter.write(buf, le);
+ assertEquals(this.getClass().getName(), buf.toString());
+ }
+
+ @Test
public void testMethodOfCaller() {
- {
- DynamicConverter<LoggingEvent> converter = new MethodOfCallerConverter();
- StringBuffer buf = new StringBuffer();
- converter.write(buf, le);
- assertEquals("testMethodOfCaller", buf.toString());
- }
+ DynamicConverter<LoggingEvent> converter = new MethodOfCallerConverter();
+ StringBuffer buf = new StringBuffer();
+ converter.write(buf, le);
+ assertEquals("testMethodOfCaller", buf.toString());
}
+ @Test
public void testFileOfCaller() {
- {
- DynamicConverter<LoggingEvent> converter = new FileOfCallerConverter();
- StringBuffer buf = new StringBuffer();
- converter.write(buf, le);
- assertEquals("ConverterTest.java", buf.toString());
- }
+ DynamicConverter<LoggingEvent> converter = new FileOfCallerConverter();
+ StringBuffer buf = new StringBuffer();
+ converter.write(buf, le);
+ assertEquals("ConverterTest.java", buf.toString());
}
+ @Test
public void testCallerData() {
{
DynamicConverter<LoggingEvent> converter = new CallerDataConverter();
@@ -262,42 +267,41 @@
}
+ @Test
public void testRelativeTime() throws Exception {
- {
- DynamicConverter<LoggingEvent> converter = new RelativeTimeConverter();
- StringBuffer buf0 = new StringBuffer();
- StringBuffer buf1 = new StringBuffer();
- LoggingEvent e0 = makeLoggingEvent(null);
- LoggingEvent e1 = makeLoggingEvent(null);
- converter.write(buf0, e0);
- converter.write(buf1, e1);
- assertEquals(buf0.toString(), buf1.toString());
- int rt0 = Integer.parseInt(buf0.toString());
- if (rt0 < 50) {
- fail("relative time should be > 50, but it is " + rt0);
- }
+ DynamicConverter<LoggingEvent> converter = new RelativeTimeConverter();
+ StringBuffer buf0 = new StringBuffer();
+ StringBuffer buf1 = new StringBuffer();
+ LoggingEvent e0 = makeLoggingEvent(null);
+ LoggingEvent e1 = makeLoggingEvent(null);
+ converter.write(buf0, e0);
+ converter.write(buf1, e1);
+ assertEquals(buf0.toString(), buf1.toString());
+ int rt0 = Integer.parseInt(buf0.toString());
+ if (rt0 < 50) {
+ fail("relative time should be > 50, but it is " + rt0);
}
}
+ @Test
public void testSyslogStart() throws Exception {
- {
- DynamicConverter<LoggingEvent> converter = new SyslogStartConverter();
- this.optionList.clear();
- this.optionList.add("MAIL");
- converter.setOptionList(this.optionList);
- converter.start();
+ DynamicConverter<LoggingEvent> converter = new SyslogStartConverter();
+ this.optionList.clear();
+ this.optionList.add("MAIL");
+ converter.setOptionList(this.optionList);
+ converter.start();
- LoggingEvent event = makeLoggingEvent(null);
+ LoggingEvent event = makeLoggingEvent(null);
- StringBuffer buf = new StringBuffer();
- converter.write(buf, event);
+ StringBuffer buf = new StringBuffer();
+ converter.write(buf, event);
- String expected = "<"
- + (SyslogConstants.LOG_MAIL + SyslogConstants.INFO_SEVERITY) + ">";
- assertTrue(buf.toString().startsWith(expected));
- }
+ String expected = "<"
+ + (SyslogConstants.LOG_MAIL + SyslogConstants.INFO_SEVERITY) + ">";
+ assertTrue(buf.toString().startsWith(expected));
}
+ @Test
public void testMDCConverter() throws Exception {
MDC.clear();
MDC.put("someKey", "someValue");
Modified: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/pattern/PackageTest.java
==============================================================================
--- logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/pattern/PackageTest.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/pattern/PackageTest.java Wed Nov 12 19:40:35 2008
@@ -10,6 +10,7 @@
package ch.qos.logback.classic.pattern;
+import junit.framework.JUnit4TestAdapter;
import junit.framework.Test;
import junit.framework.TestCase;
import junit.framework.TestSuite;
@@ -18,8 +19,8 @@
public static Test suite() {
TestSuite suite = new TestSuite();
- suite.addTestSuite(ConverterTest.class);
- suite.addTestSuite(ClassNameAbbreviatorTest.class);
+ suite.addTest(new JUnit4TestAdapter(ConverterTest.class));
+ suite.addTest(new JUnit4TestAdapter(TargetLengthBasedClassNameAbbreviatorTest.class));
suite.addTestSuite(MDCConverterTest.class);
suite.addTestSuite(MarkerConverterTest.class);
return suite;
Copied: logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/pattern/TargetLengthBasedClassNameAbbreviatorTest.java (from r1899, /logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/pattern/ClassNameAbbreviatorTest.java)
==============================================================================
--- /logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/pattern/ClassNameAbbreviatorTest.java (original)
+++ logback/trunk/logback-classic/src/test/java/ch/qos/logback/classic/pattern/TargetLengthBasedClassNameAbbreviatorTest.java Wed Nov 12 19:40:35 2008
@@ -1,147 +1,143 @@
/**
- * 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-2008, 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 junit.framework.TestCase;
+import static org.junit.Assert.*;
-import ch.qos.logback.classic.pattern.ClassNameAbbreviator;
+import org.junit.Test;
-public class ClassNameAbbreviatorTest extends TestCase {
+import ch.qos.logback.classic.pattern.TargetLengthBasedClassNameAbbreviator;
- public ClassNameAbbreviatorTest(String arg0) {
- super(arg0);
- }
-
- protected void setUp() throws Exception {
- super.setUp();
- }
+public class TargetLengthBasedClassNameAbbreviatorTest {
- protected void tearDown() throws Exception {
- super.tearDown();
- }
+ @Test
public void testShortName() {
{
- ClassNameAbbreviator abbreviator = new ClassNameAbbreviator(100);
+ TargetLengthBasedClassNameAbbreviator abbreviator = new TargetLengthBasedClassNameAbbreviator(100);
String name = "hello";
assertEquals(name, abbreviator.abbreviate(name));
}
{
- ClassNameAbbreviator abbreviator = new ClassNameAbbreviator(100);
+ TargetLengthBasedClassNameAbbreviator abbreviator = new TargetLengthBasedClassNameAbbreviator(100);
String name = "hello.world";
assertEquals(name, abbreviator.abbreviate(name));
}
}
+ @Test
public void testNoDot() {
- ClassNameAbbreviator abbreviator = new ClassNameAbbreviator(1);
+ TargetLengthBasedClassNameAbbreviator abbreviator = new TargetLengthBasedClassNameAbbreviator(1);
String name = "hello";
assertEquals(name, abbreviator.abbreviate(name));
}
+ @Test
public void testOneDot() {
{
- ClassNameAbbreviator abbreviator = new ClassNameAbbreviator(1);
+ TargetLengthBasedClassNameAbbreviator abbreviator = new TargetLengthBasedClassNameAbbreviator(1);
String name = "hello.world";
assertEquals("h.world", abbreviator.abbreviate(name));
}
{
- ClassNameAbbreviator abbreviator = new ClassNameAbbreviator(1);
+ TargetLengthBasedClassNameAbbreviator abbreviator = new TargetLengthBasedClassNameAbbreviator(1);
String name = "h.world";
assertEquals("h.world", abbreviator.abbreviate(name));
}
{
- ClassNameAbbreviator abbreviator = new ClassNameAbbreviator(1);
+ TargetLengthBasedClassNameAbbreviator abbreviator = new TargetLengthBasedClassNameAbbreviator(1);
String name = ".world";
assertEquals(".world", abbreviator.abbreviate(name));
}
}
+ @Test
public void testTwoDot() {
{
- ClassNameAbbreviator abbreviator = new ClassNameAbbreviator(1);
+ TargetLengthBasedClassNameAbbreviator abbreviator = new TargetLengthBasedClassNameAbbreviator(1);
String name = "com.logback.Foobar";
assertEquals("c.l.Foobar", abbreviator.abbreviate(name));
}
{
- ClassNameAbbreviator abbreviator = new ClassNameAbbreviator(1);
+ TargetLengthBasedClassNameAbbreviator abbreviator = new TargetLengthBasedClassNameAbbreviator(1);
String name = "c.logback.Foobar";
assertEquals("c.l.Foobar", abbreviator.abbreviate(name));
}
{
- ClassNameAbbreviator abbreviator = new ClassNameAbbreviator(1);
+ TargetLengthBasedClassNameAbbreviator abbreviator = new TargetLengthBasedClassNameAbbreviator(1);
String name = "c..Foobar";
assertEquals("c..Foobar", abbreviator.abbreviate(name));
}
{
- ClassNameAbbreviator abbreviator = new ClassNameAbbreviator(1);
+ TargetLengthBasedClassNameAbbreviator abbreviator = new TargetLengthBasedClassNameAbbreviator(1);
String name = "..Foobar";
assertEquals("..Foobar", abbreviator.abbreviate(name));
}
}
-
+
+ @Test
public void test3Dot() {
{
- ClassNameAbbreviator abbreviator = new ClassNameAbbreviator(1);
+ TargetLengthBasedClassNameAbbreviator abbreviator = new TargetLengthBasedClassNameAbbreviator(1);
String name = "com.logback.xyz.Foobar";
assertEquals("c.l.x.Foobar", abbreviator.abbreviate(name));
}
{
- ClassNameAbbreviator abbreviator = new ClassNameAbbreviator(13);
+ TargetLengthBasedClassNameAbbreviator abbreviator = new TargetLengthBasedClassNameAbbreviator(13);
String name = "com.logback.xyz.Foobar";
assertEquals("c.l.x.Foobar", abbreviator.abbreviate(name));
}
{
- ClassNameAbbreviator abbreviator = new ClassNameAbbreviator(14);
+ TargetLengthBasedClassNameAbbreviator abbreviator = new TargetLengthBasedClassNameAbbreviator(14);
String name = "com.logback.xyz.Foobar";
assertEquals("c.l.xyz.Foobar", abbreviator.abbreviate(name));
}
{
- ClassNameAbbreviator abbreviator = new ClassNameAbbreviator(15);
+ TargetLengthBasedClassNameAbbreviator abbreviator = new TargetLengthBasedClassNameAbbreviator(15);
String name = "com.logback.alligator.Foobar";
assertEquals("c.l.a.Foobar", abbreviator.abbreviate(name));
}
}
-
+ @Test
public void testXDot() {
{
- ClassNameAbbreviator abbreviator = new ClassNameAbbreviator(21);
+ TargetLengthBasedClassNameAbbreviator abbreviator = new TargetLengthBasedClassNameAbbreviator(21);
String name = "com.logback.wombat.alligator.Foobar";
assertEquals("c.l.w.a.Foobar", abbreviator.abbreviate(name));
}
{
- ClassNameAbbreviator abbreviator = new ClassNameAbbreviator(22);
+ TargetLengthBasedClassNameAbbreviator abbreviator = new TargetLengthBasedClassNameAbbreviator(22);
String name = "com.logback.wombat.alligator.Foobar";
assertEquals("c.l.w.alligator.Foobar", abbreviator.abbreviate(name));
}
{
- ClassNameAbbreviator abbreviator = new ClassNameAbbreviator(1);
+ TargetLengthBasedClassNameAbbreviator abbreviator = new TargetLengthBasedClassNameAbbreviator(1);
String name = "com.logback.wombat.alligator.tomato.Foobar";
assertEquals("c.l.w.a.t.Foobar", abbreviator.abbreviate(name));
}
{
- ClassNameAbbreviator abbreviator = new ClassNameAbbreviator(21);
+ TargetLengthBasedClassNameAbbreviator abbreviator = new TargetLengthBasedClassNameAbbreviator(21);
String name = "com.logback.wombat.alligator.tomato.Foobar";
assertEquals("c.l.w.a.tomato.Foobar", abbreviator.abbreviate(name));
}
{
- ClassNameAbbreviator abbreviator = new ClassNameAbbreviator(29);
+ TargetLengthBasedClassNameAbbreviator abbreviator = new TargetLengthBasedClassNameAbbreviator(29);
String name = "com.logback.wombat.alligator.tomato.Foobar";
assertEquals("c.l.w.alligator.tomato.Foobar", abbreviator.abbreviate(name));
}
Modified: logback/trunk/logback-site/src/site/pages/css/common.css
==============================================================================
--- logback/trunk/logback-site/src/site/pages/css/common.css (original)
+++ logback/trunk/logback-site/src/site/pages/css/common.css Wed Nov 12 19:40:35 2008
@@ -124,6 +124,11 @@
}
+/* apply to tr elements of tables which are both bodytable and dark */
+table[class="bodyTable dark"] tr {
+ background-color: #ddd;
+}
+
table.bodyTable tr.a {
background-color: #ddd;
}
@@ -178,6 +183,7 @@
color: red;
font-weight: bold;
}
+
.greenBold {
color: green;
font-weight: bold;
Modified: logback/trunk/logback-site/src/site/pages/manual/layouts.html
==============================================================================
--- logback/trunk/logback-site/src/site/pages/manual/layouts.html (original)
+++ logback/trunk/logback-site/src/site/pages/manual/layouts.html Wed Nov 12 19:40:35 2008
@@ -208,7 +208,8 @@
the logging request was sent.
</p>
<p>Here is the implementation of this class:</p>
-<div class="source"><pre>package chapter5;
+
+ <p class="source">package chapter5;
import ch.qos.logback.classic.spi.LoggingEvent;
import ch.qos.logback.core.LayoutBase;
@@ -247,7 +248,7 @@
sbuf.append(LINE_SEP);
return sbuf.toString();
}
-}</pre></div>
+}</p>
<p>The addition of the corresponding setter method is all that is
@@ -260,7 +261,7 @@
</p>
-<div class="source"><pre><configuration>
+ <p class="source"><configuration>
<appender name="STDOUT"
class="ch.qos.logback.core.ConsoleAppender">
@@ -274,25 +275,22 @@
<level value="debug" />
<appender-ref ref="STDOUT" />
</root>
-</configuration></pre></div>
+</configuration></p>
- <p>
-
- </p>
+ <p></p>
<h3><a name="ClassicPatternLayout"
href="#ClassicPatternLayout">PatternLayout</a></h3>
- <p>
- Logback classic ships with a flexible layout called <a
- href="../xref/ch/qos/logback/classic/PatternLayout.html">
- <code>PatternLayout</code></a>. As all layouts,
- <code>PatternLayout</code> takes a logging event and returns a
- <code>String</code>. However, this <code>String</code> can be
- customized at will by tweaking the conversion pattern of
- <code>PatternLayout</code>.
+ <p>Logback classic ships with a flexible layout called <a
+ href="../xref/ch/qos/logback/classic/PatternLayout.html">
+ <code>PatternLayout</code></a>. As all layouts,
+ <code>PatternLayout</code> takes a logging event and returns a
+ <code>String</code>. However, this <code>String</code> can be
+ customized at will by tweaking the conversion pattern of
+ <code>PatternLayout</code>.
</p>
<p>The conversion pattern of <code>PatternLayout</code> is closely
@@ -301,7 +299,7 @@
composed of literal text and format control expressions called
conversion specifiers. You are free to insert any literal text
within the conversion pattern. Each conversion specifier starts
- with a percent sign (%) and is followed by optional format
+ with a percent sign '%' and is followed by optional format
modifiers, a conversion word and optional parameters between
braces. The conversion word controls the type of data to use, e.g.
logger name, level, date, thread name. The format modifiers
@@ -341,25 +339,23 @@
}
}</pre></div>
- <p>
- The conversion pattern is set to be <b>"%-5level [%thread]:
- %message%n"</b>. Running PatternSample will yield the following
- output on the console.
- </p>
- <div class="source"><pre>DEBUG [main]: Message 1
-WARN [main]: Message 2</pre></div>
- <p>
- Note that in the conversion pattern <b>"%-5level [%thread]:
- %message%n"</b> there is no explicit separator between literal
- text and conversion specifiers. When parsing a conversion
- pattern,
- <code>PatternLayout</code>
- is capable of differentiating between literal text (space
- characters, the brackets, colon character) and conversion
- specifiers. In the example above, the conversion specifier
- %-5level means the level of the logging event should be left
- justified to a width of five characters. Format specifiers
- will be explained in a short moment.
+ <p>The conversion pattern is set to be <b>"%-5level [%thread]:
+ %message%n"</b>. Running PatternSample will yield the following
+ output on the console.
+ </p>
+
+ <p class="source">DEBUG [main]: Message 1
+WARN [main]: Message 2</p>
+
+ <p>Note that in the conversion pattern <b>"%-5level [%thread]:
+ %message%n"</b> there is no explicit separator between literal
+ text and conversion specifiers. When parsing a conversion pattern,
+ <code>PatternLayout</code> is capable of differentiating between
+ literal text (space characters, the brackets, colon character) and
+ conversion specifiers. In the example above, the conversion
+ specifier %-5level means the level of the logging event should be
+ left justified to a width of five characters. Format specifiers
+ will be explained in a short moment.
</p>
<p>In PatternLayout, parenthesis can be used to group conversion
@@ -402,43 +398,52 @@
the logging event.
</p>
- <p>This conversion word can take an integer as first and
+ <p>This conversion word can take an integer as its first and
only option. The converter's abbreviation algorithm will
shorten the logger name, usually without significant loss of
- meaning. The next table provides examples of the
- abbreviation algorithm in action.
+ meaning. Setting the value of this option to zero will cause
+ the conversoin specifier to return the string right to the
+ rightmost dot character. The next table provides examples of
+ the abbreviation algorithm in action.
</p>
- <table class="bodyTable" border="0" cellpadding="8">
- <tr class="a">
+ <table class="bodyTable dark" border="0" cellpadding="8">
+ <tr>
<th>Conversion specifier</th>
<th>Logger name</th>
<th>Result</th>
</tr>
- <tr class="a">
+ <tr>
<td>%logger</td>
<td>mainPackage.sub.sample.Bar</td>
<td>mainPackage.sub.sample.Bar</td>
</tr>
- <tr class="a">
+
+ <tr>
+ <td>%logger{0}</td>
+ <td>mainPackage.sub.sample.Bar</td>
+ <td>Bar</td>
+ </tr>
+
+ <tr>
<td>%logger{10}</td>
<td>mainPackage.sub.sample.Bar</td>
<td>m.s.s.Bar</td>
</tr>
- <tr class="a">
+ <tr>
<td>%logger{15}</td>
<td>mainPackage.sub.sample.Bar</td>
<td>m.s.sample.Bar</td>
</tr>
- <tr class="a">
+ <tr>
<td>%logger{16}</td>
<td>mainPackage.sub.sample.Bar</td>
<td>m.sub.sample.Bar</td>
</tr>
- <tr class="a">
+ <tr>
<td>%logger{26}</td>
<td>mainPackage.sub.sample.Bar</td>
<td>mainPackage.sub.sample.Bar</td>
@@ -459,12 +464,15 @@
</p>
<p> Just like the <em>%logger</em> conversion word above,
this word can take an interger as it's first option and use
- its abbreviation algorithm to shorten the class name. By
+ its abbreviation algorithm to shorten the class name. Zero
+ carries special meaning and w will cause the simple class
+ name to be output without its package name prefix. By
default the class name is output in full.
</p>
- <p>Generating the caller class information is not
- particularly fast. Thus, it's use should be avoided unless
- execution speed is not an issue.
+
+ <p>Generating the caller class information is not
+ particularly fast. Thus, it's use should be avoided unless
+ execution speed is not an issue.
</p>
</td>
</tr>
@@ -491,24 +499,24 @@
actual date is Friday 20th of October, 2006 and that the
author finished his meal a short while ago.</p>
- <table class="bodyTable" cellpadding="8">
- <tr class="a">
+ <table class="bodyTable dark" cellpadding="8">
+ <tr>
<th>Conversion Pattern</th>
<th>Result</th>
</tr>
- <tr class="a">
+ <tr>
<td>%date</td>
<td>2006-10-20 14:46:49,812</td>
</tr>
- <tr class="a">
+ <tr>
<td>%date{ISO8601}</td>
<td>2006-10-20 14:46:49,812</td>
</tr>
- <tr class="a">
+ <tr>
<td>%date{HH:mm:ss.SSS}</td>
<td>14:46:49.812</td>
</tr>
- <tr class="a">
+ <tr>
<td>%date{dd MMM yyyy ;HH:mm:ss.SSS}</td>
<td>20 oct. 2006;14:46:49.812 </td>
</tr>
@@ -522,7 +530,7 @@
</td>
<td>
- <p> Used to output the file name of the Java source file
+ <p>Used to output the file name of the Java source file
where the logging request was issued.
</p>
Modified: logback/trunk/logback-site/src/site/pages/news.html
==============================================================================
--- logback/trunk/logback-site/src/site/pages/news.html (original)
+++ logback/trunk/logback-site/src/site/pages/news.html Wed Nov 12 19:40:35 2008
@@ -45,29 +45,35 @@
<code>NullPointerException</code> would be thrown.
</p>
- <p>In reponse to <a
- href="http://jira.qos.ch/browse/LBCLASSIC-61">LBCLASSIC-61</a>, <a
- href="http://jira.qos.ch/browse/LBCLASSIC-33">LBCLASSIC-33</a>, <a
- href="http://jira.qos.ch/browse/LBCLASSIC-14">LBCLASSIC-24</a> and
- <a href="http://jira.qos.ch/browse/LBCLASSIC-24">LBCLASSIC-14</a>
- JMXConfigurator has been redesigned.
- </p>
+ <p>In reponse to <a
+ href="http://jira.qos.ch/browse/LBCLASSIC-61">LBCLASSIC-61</a>, <a
+ href="http://jira.qos.ch/browse/LBCLASSIC-33">LBCLASSIC-33</a>, <a
+ href="http://jira.qos.ch/browse/LBCLASSIC-14">LBCLASSIC-24</a> and
+ <a href="http://jira.qos.ch/browse/LBCLASSIC-24">LBCLASSIC-14</a>
+ JMXConfigurator has been redesigned.
+ </p>
- <p>Fixed improvement request <a
- href="http://jira.qos.ch/browse/LBCLASSIC-59">LBCLASSIC-59</a>
- relation to StatusListeners, originally submitted by Anton Tagunov.
- </p>
+ <p>Fixed improvement request <a
+ href="http://jira.qos.ch/browse/LBCLASSIC-59">LBCLASSIC-59</a>
+ relation to StatusListeners, originally submitted by Anton Tagunov.
+ </p>
- <p>In response to <a href="http://jira.qos.ch/browse/LBCLASSIC-54">
- LBCLASSIC-54</a> support for turbo filters has refactored. The
- present code is safe under concurrent access while still offering
- good performance.
- </p>
+ <p>The logger and class name converters now consider zero as
+ having special meaning, and will return the simple class name,
+ removing the package name prefix. This feature was asked by
+ Silvano Maffeis.</p>
+
+ <p>In response to <a
+ href="http://jira.qos.ch/browse/LBCLASSIC-54"> LBCLASSIC-54</a>
+ support for turbo filters has refactored. The present code is safe
+ under concurrent access while still offering good performance.
+ </p>
- <p>Fixed <a href="http://jira.qos.ch/browse/LBCORE-43">LBCORE-43</a>
- reported by Bruno Navert. Configuration files can now look up
- property files from classpath resources.
- </p>
+ <p>Fixed <a
+ href="http://jira.qos.ch/browse/LBCORE-43">LBCORE-43</a> reported
+ by Bruno Navert. Configuration files can now look up property
+ files from classpath resources.
+ </p>
<!-- ======================== minor ================== -->
More information about the logback-dev
mailing list