Fixing logging level filtering + adding more severity level tests

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@902 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Joakim Erdfelt 2009-09-15 20:38:42 +00:00
parent 432ab6605a
commit caea709d83
14 changed files with 311 additions and 45 deletions

View File

@ -42,6 +42,12 @@ public class CentralLogger extends MarkerIgnoringBase
private void log(Severity severity, String message, Throwable t)
{
if (!level.isEnabled(severity))
{
// Don't log level
return;
}
String now = new SimpleDateFormat(dateFormat).format(new Date());
for (Appender appender : appenders)
@ -59,18 +65,33 @@ public class CentralLogger extends MarkerIgnoringBase
private void logFormatted(Severity severity, String format, Object arg)
{
if (!level.isEnabled(severity))
{
// Don't log level
return;
}
String msg = MessageFormatter.format(format,arg);
log(severity,msg,null);
}
private void logFormatted(Severity severity, String format, Object arg1, Object arg2)
{
if (!level.isEnabled(severity))
{
// Don't log level
return;
}
String msg = MessageFormatter.format(format,arg1,arg2);
log(severity,msg,null);
}
private void logFormatted(Severity severity, String format, Object[] argArray)
{
if (!level.isEnabled(severity))
{
// Don't log level
return;
}
String msg = MessageFormatter.arrayFormat(format,argArray);
log(severity,msg,null);
}

View File

@ -101,7 +101,7 @@
<profiles>
<profile>
<id>copy-fresh-webapps</id>
<id>copy-test-webapps</id>
<build>
<plugins>
<plugin>
@ -109,7 +109,7 @@
<artifactId>maven-dependency-plugin</artifactId>
<executions>
<execution>
<id>copy-testing-wars</id>
<id>testwarcopy</id>
<phase>validate</phase>
<goals>
<goal>copy</goal>

View File

@ -16,6 +16,7 @@
package org.eclipse.jetty.tests.webapp;
import java.io.FileNotFoundException;
import java.io.IOException;
import javax.servlet.ServletException;
@ -32,6 +33,7 @@ import org.apache.commons.logging.LogFactory;
public class LoggingServlet extends HttpServlet
{
private static final long serialVersionUID = 1L;
private static final String LOGID = "LoggingServlet(commons-logging)";
private Log log = LogFactory.getLog(LoggingServlet.class);
/**
@ -39,16 +41,25 @@ public class LoggingServlet extends HttpServlet
*/
public LoggingServlet()
{
log.debug("LoggingServlet(commons-logging) initialized");
log.debug(LOGID + " initialized");
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
log.info("LoggingServlet(commons-logging) GET requested");
log.info(LOGID + " GET requested");
log.warn(LOGID + " Slightly warn, with a chance of log events");
log.error(LOGID + " Nothing is (intentionally) being output by this Servlet");
IOException severe = new FileNotFoundException("A file cannot be found");
log.fatal(LOGID + " Whoops (intentionally) causing a Throwable",severe);
}
}

View File

@ -16,6 +16,7 @@
package org.eclipse.jetty.tests.webapp;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.logging.Level;
import java.util.logging.Logger;
@ -31,6 +32,7 @@ import javax.servlet.http.HttpServletResponse;
public class LoggingServlet extends HttpServlet
{
private static final long serialVersionUID = 1L;
private static final String LOGID = "LoggingServlet(java)";
private Logger log = Logger.getLogger(LoggingServlet.class.getName());
/**
@ -38,7 +40,7 @@ public class LoggingServlet extends HttpServlet
*/
public LoggingServlet()
{
log.log(Level.FINE,"LoggingServlet(java) initialized");
log.log(Level.FINE,LOGID + " initialized");
}
/**
@ -47,6 +49,15 @@ public class LoggingServlet extends HttpServlet
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
log.log(Level.INFO,"LoggingServlet(java) GET requested");
log.log(Level.INFO,LOGID + " GET requested");
log.log(Level.WARNING,LOGID + " Slightly warn, with a chance of log events");
log.log(Level.WARNING,LOGID + " Nothing is (intentionally) being output by this Servlet");
IOException severe = new FileNotFoundException("A file cannot be found");
log.log(Level.SEVERE,LOGID + " Whoops (intentionally) causing a Throwable",severe);
}
}

View File

@ -16,6 +16,7 @@
package org.eclipse.jetty.tests.webapp;
import java.io.FileNotFoundException;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
@ -30,6 +31,7 @@ import org.apache.log4j.Logger;
public class LoggingServlet extends HttpServlet
{
private static final long serialVersionUID = 1L;
private static final String LOGID = "LoggingServlet(log4j)";
private Logger log = Logger.getLogger(LoggingServlet.class);
/**
@ -37,15 +39,24 @@ public class LoggingServlet extends HttpServlet
*/
public LoggingServlet()
{
log.debug("LoggingServlet(log4j) initialized");
log.debug(LOGID + " initialized");
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
log.info("LoggingServlet(log4j) GET requested");
log.info(LOGID + " GET requested");
log.warn(LOGID + " Slightly warn, with a chance of log events");
log.error(LOGID + " Nothing is (intentionally) being output by this Servlet");
IOException severe = new FileNotFoundException("A file cannot be found");
log.fatal(LOGID + " Whoops (intentionally) causing a Throwable",severe);
}
}

View File

@ -16,6 +16,7 @@
package org.eclipse.jetty.tests.webapp;
import java.io.FileNotFoundException;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
@ -31,6 +32,7 @@ import org.slf4j.LoggerFactory;
public class LoggingServlet extends HttpServlet
{
private static final long serialVersionUID = 1L;
private static final String LOGID = "LoggingServlet(slf4j)";
private Logger log = LoggerFactory.getLogger(LoggingServlet.class);
/**
@ -38,16 +40,25 @@ public class LoggingServlet extends HttpServlet
*/
public LoggingServlet()
{
log.debug("LoggingServlet(slf4j) initialized");
log.debug(LOGID + " initialized");
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
log.info("LoggingServlet(slf4j) GET requested");
log.info(LOGID + " GET requested");
log.warn(LOGID + " Slightly warn, with a chance of log events");
log.error(LOGID + " Nothing is (intentionally) being output by this Servlet");
IOException severe = new FileNotFoundException("A file cannot be found");
log.error(LOGID + " Whoops (intentionally) causing a Throwable",severe);
}
}

View File

@ -15,7 +15,10 @@
// ========================================================================
package org.eclipse.jetty.webapp.logging;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import junit.framework.TestCase;
@ -28,7 +31,7 @@ public class CentralizedLoggingTest extends TestCase
private static final String LOGGING_SERVLET_ID = "org.eclipse.jetty.tests.webapp.LoggingServlet";
private XmlConfiguredJetty jetty;
private void assertContainsLogEvents(TestAppender capturedEvents, LogEvent[] expectedLogs)
private void assertContainsLogEvents(TestAppender capturedEvents, List<LogEvent> expectedLogs)
{
for (LogEvent expectedEvent : expectedLogs)
{
@ -73,15 +76,37 @@ public class CentralizedLoggingTest extends TestCase
SimpleRequest.get(jetty,"/dummy-webapp-logging-slf4j/logging");
SimpleRequest.get(jetty,"/dummy-webapp-logging-java/logging");
TestAppender.LogEvent expectedLogs[] =
{ new LogEvent(Severity.DEBUG,LOGGING_SERVLET_ID,"LoggingServlet(log4j) initialized"),
new LogEvent(Severity.INFO,LOGGING_SERVLET_ID,"LoggingServlet(log4j) GET requested"),
new LogEvent(Severity.DEBUG,LOGGING_SERVLET_ID,"LoggingServlet(slf4j) initialized"),
new LogEvent(Severity.INFO,LOGGING_SERVLET_ID,"LoggingServlet(slf4j) GET requested"),
new LogEvent(Severity.DEBUG,LOGGING_SERVLET_ID,"LoggingServlet(commons-logging) initialized"),
new LogEvent(Severity.INFO,LOGGING_SERVLET_ID,"LoggingServlet(commons-logging) GET requested"),
new LogEvent(Severity.DEBUG,LOGGING_SERVLET_ID,"LoggingServlet(java) initialized"),
new LogEvent(Severity.INFO,LOGGING_SERVLET_ID,"LoggingServlet(java) GET requested") };
String prefix = "LoggingServlet(commons-logging)";
List<LogEvent> expectedLogs = new ArrayList<LogEvent>();
// expectedLogs.add(new LogEvent(Severity.DEBUG,LOGGING_SERVLET_ID,prefix + " initialized"));
expectedLogs.add(new LogEvent(Severity.INFO,LOGGING_SERVLET_ID,prefix + " GET requested"));
expectedLogs.add(new LogEvent(Severity.WARN,LOGGING_SERVLET_ID,prefix + " Slightly warn, with a chance of log events"));
expectedLogs.add(new LogEvent(Severity.ERROR,LOGGING_SERVLET_ID,prefix + " Nothing is (intentionally) being output by this Servlet"));
expectedLogs.add(new LogEvent(Severity.ERROR,LOGGING_SERVLET_ID,prefix + " Whoops (intentionally) causing a Throwable")
.expectedThrowable(new FileNotFoundException("A file cannot be found")));
prefix = "LoggingServlet(log4j)";
// expectedLogs.add(new LogEvent(Severity.DEBUG,LOGGING_SERVLET_ID,prefix + " initialized"));
expectedLogs.add(new LogEvent(Severity.INFO,LOGGING_SERVLET_ID,prefix + " GET requested"));
expectedLogs.add(new LogEvent(Severity.WARN,LOGGING_SERVLET_ID,prefix + " Slightly warn, with a chance of log events"));
expectedLogs.add(new LogEvent(Severity.ERROR,LOGGING_SERVLET_ID,prefix + " Nothing is (intentionally) being output by this Servlet"));
expectedLogs.add(new LogEvent(Severity.ERROR,LOGGING_SERVLET_ID,prefix + " Whoops (intentionally) causing a Throwable")
.expectedThrowable(new FileNotFoundException("A file cannot be found")));
prefix = "LoggingServlet(java)";
// expectedLogs.add(new LogEvent(Severity.DEBUG,LOGGING_SERVLET_ID,prefix + " initialized"));
expectedLogs.add(new LogEvent(Severity.INFO,LOGGING_SERVLET_ID,prefix + " GET requested"));
expectedLogs.add(new LogEvent(Severity.WARN,LOGGING_SERVLET_ID,prefix + " Slightly warn, with a chance of log events"));
expectedLogs.add(new LogEvent(Severity.WARN,LOGGING_SERVLET_ID,prefix + " Nothing is (intentionally) being output by this Servlet"));
expectedLogs.add(new LogEvent(Severity.ERROR,LOGGING_SERVLET_ID,prefix + " Whoops (intentionally) causing a Throwable")
.expectedThrowable(new FileNotFoundException("A file cannot be found")));
prefix = "LoggingServlet(slf4j)";
// expectedLogs.add(new LogEvent(Severity.DEBUG,LOGGING_SERVLET_ID,prefix + " initialized"));
expectedLogs.add(new LogEvent(Severity.INFO,LOGGING_SERVLET_ID,prefix + " GET requested"));
expectedLogs.add(new LogEvent(Severity.WARN,LOGGING_SERVLET_ID,prefix + " Slightly warn, with a chance of log events"));
expectedLogs.add(new LogEvent(Severity.ERROR,LOGGING_SERVLET_ID,prefix + " Nothing is (intentionally) being output by this Servlet"));
expectedLogs.add(new LogEvent(Severity.ERROR,LOGGING_SERVLET_ID,prefix + " Whoops (intentionally) causing a Throwable")
.expectedThrowable(new FileNotFoundException("A file cannot be found")));
assertContainsLogEvents(testAppender,expectedLogs);
assertContainsLogEvents(testAppender,expectedLogs);
}

View File

@ -16,6 +16,7 @@
package org.eclipse.jetty.webapp.logging;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.List;
@ -40,7 +41,7 @@ public class EmbeddedCentralizedLoggingTest extends TestCase
private static final String LOGGING_SERVLET_ID = "org.eclipse.jetty.tests.webapp.LoggingServlet";
private TestAppender testAppender;
private void assertContainsLogEvents(TestAppender capturedEvents, LogEvent[] expectedLogs)
private void assertContainsLogEvents(TestAppender capturedEvents, List<LogEvent> expectedLogs)
{
for (LogEvent expectedEvent : expectedLogs)
{
@ -145,15 +146,35 @@ public class EmbeddedCentralizedLoggingTest extends TestCase
server.stop();
TestAppender.LogEvent expectedLogs[] =
{ new LogEvent(Severity.DEBUG,LOGGING_SERVLET_ID,"LoggingServlet(log4j) initialized"),
new LogEvent(Severity.INFO,LOGGING_SERVLET_ID,"LoggingServlet(log4j) GET requested"),
new LogEvent(Severity.DEBUG,LOGGING_SERVLET_ID,"LoggingServlet(slf4j) initialized"),
new LogEvent(Severity.INFO,LOGGING_SERVLET_ID,"LoggingServlet(slf4j) GET requested"),
new LogEvent(Severity.DEBUG,LOGGING_SERVLET_ID,"LoggingServlet(commons-logging) initialized"),
new LogEvent(Severity.INFO,LOGGING_SERVLET_ID,"LoggingServlet(commons-logging) GET requested"),
new LogEvent(Severity.DEBUG,LOGGING_SERVLET_ID,"LoggingServlet(java) initialized"),
new LogEvent(Severity.INFO,LOGGING_SERVLET_ID,"LoggingServlet(java) GET requested") };
String prefix = "LoggingServlet(commons-logging)";
List<LogEvent> expectedLogs = new ArrayList<LogEvent>();
// expectedLogs.add(new LogEvent(Severity.DEBUG,LOGGING_SERVLET_ID,prefix + " initialized"));
expectedLogs.add(new LogEvent(Severity.INFO,LOGGING_SERVLET_ID,prefix + " GET requested"));
expectedLogs.add(new LogEvent(Severity.WARN,LOGGING_SERVLET_ID,prefix + " Slightly warn, with a chance of log events"));
expectedLogs.add(new LogEvent(Severity.ERROR,LOGGING_SERVLET_ID,prefix + " Nothing is (intentionally) being output by this Servlet"));
expectedLogs.add(new LogEvent(Severity.ERROR,LOGGING_SERVLET_ID,prefix + " Whoops (intentionally) causing a Throwable")
.expectedThrowable(new FileNotFoundException("A file cannot be found")));
prefix = "LoggingServlet(log4j)";
// expectedLogs.add(new LogEvent(Severity.DEBUG,LOGGING_SERVLET_ID,prefix + " initialized"));
expectedLogs.add(new LogEvent(Severity.INFO,LOGGING_SERVLET_ID,prefix + " GET requested"));
expectedLogs.add(new LogEvent(Severity.WARN,LOGGING_SERVLET_ID,prefix + " Slightly warn, with a chance of log events"));
expectedLogs.add(new LogEvent(Severity.ERROR,LOGGING_SERVLET_ID,prefix + " Nothing is (intentionally) being output by this Servlet"));
expectedLogs.add(new LogEvent(Severity.ERROR,LOGGING_SERVLET_ID,prefix + " Whoops (intentionally) causing a Throwable")
.expectedThrowable(new FileNotFoundException("A file cannot be found")));
prefix = "LoggingServlet(java)";
// expectedLogs.add(new LogEvent(Severity.DEBUG,LOGGING_SERVLET_ID,prefix + " initialized"));
expectedLogs.add(new LogEvent(Severity.INFO,LOGGING_SERVLET_ID,prefix + " GET requested"));
expectedLogs.add(new LogEvent(Severity.WARN,LOGGING_SERVLET_ID,prefix + " Slightly warn, with a chance of log events"));
expectedLogs.add(new LogEvent(Severity.WARN,LOGGING_SERVLET_ID,prefix + " Nothing is (intentionally) being output by this Servlet"));
expectedLogs.add(new LogEvent(Severity.ERROR,LOGGING_SERVLET_ID,prefix + " Whoops (intentionally) causing a Throwable")
.expectedThrowable(new FileNotFoundException("A file cannot be found")));
prefix = "LoggingServlet(slf4j)";
// expectedLogs.add(new LogEvent(Severity.DEBUG,LOGGING_SERVLET_ID,prefix + " initialized"));
expectedLogs.add(new LogEvent(Severity.INFO,LOGGING_SERVLET_ID,prefix + " GET requested"));
expectedLogs.add(new LogEvent(Severity.WARN,LOGGING_SERVLET_ID,prefix + " Slightly warn, with a chance of log events"));
expectedLogs.add(new LogEvent(Severity.ERROR,LOGGING_SERVLET_ID,prefix + " Nothing is (intentionally) being output by this Servlet"));
expectedLogs.add(new LogEvent(Severity.ERROR,LOGGING_SERVLET_ID,prefix + " Whoops (intentionally) causing a Throwable")
.expectedThrowable(new FileNotFoundException("A file cannot be found")));
assertContainsLogEvents(testAppender,expectedLogs);
}
@ -168,9 +189,14 @@ public class EmbeddedCentralizedLoggingTest extends TestCase
server.stop();
TestAppender.LogEvent expectedLogs[] =
{ new LogEvent(Severity.DEBUG,LOGGING_SERVLET_ID,"LoggingServlet(commons-logging) initialized"),
new LogEvent(Severity.INFO,LOGGING_SERVLET_ID,"LoggingServlet(commons-logging) GET requested") };
String prefix = "LoggingServlet(commons-logging)";
List<LogEvent> expectedLogs = new ArrayList<LogEvent>();
// expectedLogs.add(new LogEvent(Severity.DEBUG,LOGGING_SERVLET_ID,prefix + " initialized"));
expectedLogs.add(new LogEvent(Severity.INFO,LOGGING_SERVLET_ID,prefix + " GET requested"));
expectedLogs.add(new LogEvent(Severity.WARN,LOGGING_SERVLET_ID,prefix + " Slightly warn, with a chance of log events"));
expectedLogs.add(new LogEvent(Severity.ERROR,LOGGING_SERVLET_ID,prefix + " Nothing is (intentionally) being output by this Servlet"));
expectedLogs.add(new LogEvent(Severity.ERROR,LOGGING_SERVLET_ID,prefix + " Whoops (intentionally) causing a Throwable")
.expectedThrowable(new FileNotFoundException("A file cannot be found")));
assertContainsLogEvents(testAppender,expectedLogs);
}
@ -185,9 +211,14 @@ public class EmbeddedCentralizedLoggingTest extends TestCase
server.stop();
TestAppender.LogEvent expectedLogs[] =
{ new LogEvent(Severity.DEBUG,LOGGING_SERVLET_ID,"LoggingServlet(java) initialized"),
new LogEvent(Severity.INFO,LOGGING_SERVLET_ID,"LoggingServlet(java) GET requested") };
String prefix = "LoggingServlet(java)";
List<LogEvent> expectedLogs = new ArrayList<LogEvent>();
// expectedLogs.add(new LogEvent(Severity.DEBUG,LOGGING_SERVLET_ID,prefix + " initialized"));
expectedLogs.add(new LogEvent(Severity.INFO,LOGGING_SERVLET_ID,prefix + " GET requested"));
expectedLogs.add(new LogEvent(Severity.WARN,LOGGING_SERVLET_ID,prefix + " Slightly warn, with a chance of log events"));
expectedLogs.add(new LogEvent(Severity.WARN,LOGGING_SERVLET_ID,prefix + " Nothing is (intentionally) being output by this Servlet"));
expectedLogs.add(new LogEvent(Severity.ERROR,LOGGING_SERVLET_ID,prefix + " Whoops (intentionally) causing a Throwable")
.expectedThrowable(new FileNotFoundException("A file cannot be found")));
assertContainsLogEvents(testAppender,expectedLogs);
}
@ -202,9 +233,14 @@ public class EmbeddedCentralizedLoggingTest extends TestCase
server.stop();
TestAppender.LogEvent expectedLogs[] =
{ new LogEvent(Severity.DEBUG,LOGGING_SERVLET_ID,"LoggingServlet(log4j) initialized"),
new LogEvent(Severity.INFO,LOGGING_SERVLET_ID,"LoggingServlet(log4j) GET requested") };
String prefix = "LoggingServlet(log4j)";
List<LogEvent> expectedLogs = new ArrayList<LogEvent>();
// expectedLogs.add(new LogEvent(Severity.DEBUG,LOGGING_SERVLET_ID,prefix + " initialized"));
expectedLogs.add(new LogEvent(Severity.INFO,LOGGING_SERVLET_ID,prefix + " GET requested"));
expectedLogs.add(new LogEvent(Severity.WARN,LOGGING_SERVLET_ID,prefix + " Slightly warn, with a chance of log events"));
expectedLogs.add(new LogEvent(Severity.ERROR,LOGGING_SERVLET_ID,prefix + " Nothing is (intentionally) being output by this Servlet"));
expectedLogs.add(new LogEvent(Severity.ERROR,LOGGING_SERVLET_ID,prefix + " Whoops (intentionally) causing a Throwable")
.expectedThrowable(new FileNotFoundException("A file cannot be found")));
assertContainsLogEvents(testAppender,expectedLogs);
}
@ -219,9 +255,14 @@ public class EmbeddedCentralizedLoggingTest extends TestCase
server.stop();
TestAppender.LogEvent expectedLogs[] =
{ new LogEvent(Severity.DEBUG,LOGGING_SERVLET_ID,"LoggingServlet(slf4j) initialized"),
new LogEvent(Severity.INFO,LOGGING_SERVLET_ID,"LoggingServlet(slf4j) GET requested") };
String prefix = "LoggingServlet(slf4j)";
List<LogEvent> expectedLogs = new ArrayList<LogEvent>();
// expectedLogs.add(new LogEvent(Severity.DEBUG,LOGGING_SERVLET_ID,prefix + " initialized"));
expectedLogs.add(new LogEvent(Severity.INFO,LOGGING_SERVLET_ID,prefix + " GET requested"));
expectedLogs.add(new LogEvent(Severity.WARN,LOGGING_SERVLET_ID,prefix + " Slightly warn, with a chance of log events"));
expectedLogs.add(new LogEvent(Severity.ERROR,LOGGING_SERVLET_ID,prefix + " Nothing is (intentionally) being output by this Servlet"));
expectedLogs.add(new LogEvent(Severity.ERROR,LOGGING_SERVLET_ID,prefix + " Whoops (intentionally) causing a Throwable")
.expectedThrowable(new FileNotFoundException("A file cannot be found")));
assertContainsLogEvents(testAppender,expectedLogs);
}

View File

@ -50,6 +50,119 @@ public class TestAppender implements Appender
this(null,severity,name,message,null);
}
public LogEvent expectedThrowable(Throwable t)
{
this.t = t;
return this;
}
@Override
public int hashCode()
{
final int prime = 31;
int result = 1;
result = prime * result + ((message == null)?0:message.hashCode());
result = prime * result + ((name == null)?0:name.hashCode());
result = prime * result + ((severity == null)?0:severity.hashCode());
if (t != null)
{
result = prime * result + t.getClass().hashCode();
if (t.getMessage() != null)
{
result = prime * result + t.getMessage().hashCode();
}
else
{
result = prime * result + 0;
}
}
else
{
result = prime * result + 0;
}
return result;
}
@Override
public boolean equals(Object obj)
{
if (this == obj)
{
return true;
}
if (obj == null)
{
return false;
}
if (getClass() != obj.getClass())
{
return false;
}
LogEvent other = (LogEvent)obj;
if (message == null)
{
if (other.message != null)
{
return false;
}
}
else if (!message.equals(other.message))
{
return false;
}
if (name == null)
{
if (other.name != null)
{
return false;
}
}
else if (!name.equals(other.name))
{
return false;
}
if (severity == null)
{
if (other.severity != null)
{
return false;
}
}
else if (!severity.equals(other.severity))
{
return false;
}
// Throwable
if (t == null)
{
if (other.t != null)
{
return false;
}
}
else
{
if (!t.getClass().equals(other.t.getClass()))
{
return false;
}
if (t.getMessage() == null)
{
if (other.t.getMessage() != null)
{
return false;
}
}
else if (!t.getMessage().equals(other.t.getMessage()))
{
return false;
}
}
return true;
}
@Override
public String toString()
{
@ -57,6 +170,11 @@ public class TestAppender implements Appender
buf.append(severity.name()).append("|");
buf.append(name).append("|");
buf.append(message);
if (t != null)
{
buf.append("|").append(t.getClass().getName());
buf.append("(\"").append(t.getMessage()).append("\")");
}
return buf.toString();
}
}
@ -95,6 +213,7 @@ public class TestAppender implements Appender
public boolean contains(LogEvent expectedEvent)
{
/*
// System.out.println("Looking for: " + expectedEvent);
for (LogEvent event : events)
{
@ -107,12 +226,27 @@ public class TestAppender implements Appender
{
continue; // not a match. skip.
}
if (expectedEvent.t != null)
{
if (event.t == null)
{
continue; // not a match. skip.
}
if (!event.t.getClass().equals(expectedEvent.t.getClass()))
{
continue; // not a match. skip.
}
if (!event.t.getMessage().equals(expectedEvent.t.getMessage()))
{
continue; // not a match. skip.
}
}
if (event.message.equals(expectedEvent.message))
{
return true;
}
}
return false;
}*/
return events.contains(expectedEvent);
}
public List<LogEvent> getEvents()

View File

@ -1,4 +1,5 @@
root.level=DEBUG
# Intentionally NOT get DEBUG messages
root.level=INFO
root.appenders=testing
appender.console.class=org.eclipse.jetty.logging.impl.ConsoleAppender