JETTY-1129
git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@995 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
parent
c0c3e110f6
commit
3a9a33565b
|
@ -241,7 +241,7 @@ public class StdErrLog implements Logger
|
|||
}
|
||||
else
|
||||
{
|
||||
format(msg.substring(i1+2));
|
||||
format(msg.substring(i0+2));
|
||||
if (arg1!=null)
|
||||
{
|
||||
_buffer.append(' ');
|
||||
|
|
|
@ -13,21 +13,138 @@
|
|||
|
||||
package org.eclipse.jetty.util.log;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.PrintStream;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
|
||||
public class LogTest extends TestCase
|
||||
{
|
||||
public void testLoggerLog()
|
||||
PrintStream _orig= System.err;
|
||||
ByteArrayOutputStream _out = new ByteArrayOutputStream();
|
||||
PrintStream _pout = new PrintStream(_out);
|
||||
|
||||
|
||||
@Override
|
||||
public void setUp()
|
||||
{
|
||||
Logger log=new LoggerLog(Log.getLogger("test"));
|
||||
System.setErr(_pout);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tearDown()
|
||||
{
|
||||
System.setErr(_orig);
|
||||
}
|
||||
|
||||
private void logNotContains(String text)
|
||||
{
|
||||
_pout.flush();
|
||||
String err = _out.toString();
|
||||
_out.reset();
|
||||
|
||||
if (err.indexOf(text)<0)
|
||||
return;
|
||||
|
||||
_orig.println("FAIL '"+text+"' in '"+err+"'");
|
||||
|
||||
assertTrue(false);
|
||||
}
|
||||
|
||||
private void logContains(String text)
|
||||
{
|
||||
_pout.flush();
|
||||
String err = _out.toString();
|
||||
_out.reset();
|
||||
|
||||
if (err.indexOf(text)>=0)
|
||||
return;
|
||||
|
||||
_orig.println("FAIL '"+text+"' not in '"+err+"'");
|
||||
assertTrue(false);
|
||||
}
|
||||
|
||||
public void testStdErrLogFormat()
|
||||
{
|
||||
StdErrLog log = new StdErrLog("test");
|
||||
|
||||
log.info("testing:{},{}","test","format");
|
||||
logContains("INFO:test:testing:test,format");
|
||||
|
||||
log.info("testing:{}","test","format");
|
||||
logContains("INFO:test:testing:test format");
|
||||
|
||||
log.info("testing","test","format");
|
||||
logContains("INFO:test:testing test format");
|
||||
|
||||
log.info("testing:{},{}","test",null);
|
||||
logContains("INFO:test:testing:test,null");
|
||||
|
||||
log.info("testing {} {}",null,null);
|
||||
logContains("INFO:test:testing null null");
|
||||
|
||||
log.info("testing:{}",null,null);
|
||||
logContains("INFO:test:testing:null");
|
||||
|
||||
log.info("testing",null,null);
|
||||
logContains("INFO:test:testing");
|
||||
}
|
||||
|
||||
public void testStdErrLogDebug()
|
||||
{
|
||||
StdErrLog log = new StdErrLog("xxx");
|
||||
|
||||
log.setDebugEnabled(true);
|
||||
log.debug("testing {} {}","LoggerLog","debug");
|
||||
log.info("testing {} {}","LoggerLog","info");
|
||||
log.warn("testing {} {}","LoggerLog","warn");
|
||||
log.debug("testing {} {}","test","debug");
|
||||
logContains("DBUG:xxx:testing test debug");
|
||||
|
||||
log.info("testing {} {}","test","info");
|
||||
logContains("INFO:xxx:testing test info");
|
||||
|
||||
log.warn("testing {} {}","test","warn");
|
||||
logContains("WARN:xxx:testing test warn");
|
||||
|
||||
log.setDebugEnabled(false);
|
||||
log.debug("YOU SHOULD NOT SEE THIS!",null,null);
|
||||
logNotContains("YOU SHOULD NOT SEE THIS!");
|
||||
}
|
||||
|
||||
public void testStdErrLogName()
|
||||
{
|
||||
StdErrLog log = new StdErrLog("test");
|
||||
|
||||
Logger next=log.getLogger("next");
|
||||
next.info("testing {} {}","next","info");
|
||||
logContains(":test.next:testing next info");
|
||||
|
||||
}
|
||||
|
||||
public void testStdErrThrowable()
|
||||
{
|
||||
Throwable th = new Throwable("Message");
|
||||
|
||||
th.printStackTrace();
|
||||
_pout.flush();
|
||||
String ths = _out.toString();
|
||||
_out.reset();
|
||||
|
||||
|
||||
StdErrLog log = new StdErrLog("test");
|
||||
log.warn("ex",th);
|
||||
|
||||
logContains(ths);
|
||||
|
||||
th = new Throwable("Message with \033 escape");
|
||||
|
||||
log.warn("ex",th);
|
||||
logNotContains("Message with \033 escape");
|
||||
log.info(th.toString());
|
||||
logNotContains("Message with \033 escape");
|
||||
|
||||
log.warn("ex",th);
|
||||
logContains("Message with ? escape");
|
||||
log.info(th.toString());
|
||||
logContains("Message with ? escape");
|
||||
|
||||
log=log.getLogger("next");
|
||||
log.info("testing {} {}","LoggerLog","info");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue