293739 Hide stacks in named log testing. Various other minor log cleanups in output.
This commit is contained in:
parent
33fa7afb47
commit
45148353ec
|
@ -28,6 +28,7 @@ import javax.servlet.http.HttpServletResponse;
|
|||
|
||||
import org.eclipse.jetty.io.Buffer;
|
||||
import org.eclipse.jetty.server.Connector;
|
||||
import org.eclipse.jetty.server.HttpConnection;
|
||||
import org.eclipse.jetty.server.Request;
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.handler.AbstractHandler;
|
||||
|
@ -322,7 +323,7 @@ public abstract class AbstractHttpExchangeCancelTest
|
|||
{
|
||||
try
|
||||
{
|
||||
((StdErrLog)Log.getLog()).setHideStacks(!LOG.isDebugEnabled());
|
||||
((StdErrLog)Log.getLogger(HttpConnection.class)).setHideStacks(true);
|
||||
TestHttpExchange exchange = new TestHttpExchange();
|
||||
exchange.setAddress(newAddress());
|
||||
exchange.setRequestURI("/?action=throw");
|
||||
|
@ -337,7 +338,7 @@ public abstract class AbstractHttpExchangeCancelTest
|
|||
}
|
||||
finally
|
||||
{
|
||||
((StdErrLog)Log.getLog()).setHideStacks(false);
|
||||
((StdErrLog)Log.getLogger(HttpConnection.class)).setHideStacks(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -139,36 +139,37 @@ public class ProxyFakeTunnelTest extends ProxyTunnellingTest
|
|||
}
|
||||
out.flush();
|
||||
|
||||
System.err.println(toserver);
|
||||
final InputStream from = toserver.getInputStream();
|
||||
|
||||
Thread copy = new Thread()
|
||||
if (toserver!=null)
|
||||
{
|
||||
public void run()
|
||||
final InputStream from = toserver.getInputStream();
|
||||
|
||||
Thread copy = new Thread()
|
||||
{
|
||||
try
|
||||
{
|
||||
IO.copy(from,out);
|
||||
out.close();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
}
|
||||
finally
|
||||
public void run()
|
||||
{
|
||||
try
|
||||
{
|
||||
IO.copy(from,out);
|
||||
out.close();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
}
|
||||
finally
|
||||
{
|
||||
try
|
||||
{
|
||||
out.close();
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
copy.setDaemon(true);
|
||||
copy.start();
|
||||
|
||||
};
|
||||
copy.setDaemon(true);
|
||||
copy.start();
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
|
|
|
@ -263,14 +263,19 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
|
|||
{
|
||||
public void run()
|
||||
{
|
||||
SelectSet set=_selectSet[id];
|
||||
String name=Thread.currentThread().getName();
|
||||
int priority=Thread.currentThread().getPriority();
|
||||
try
|
||||
{
|
||||
SelectSet[] sets=_selectSet;
|
||||
if (sets==null)
|
||||
return;
|
||||
SelectSet set=sets[id];
|
||||
|
||||
Thread.currentThread().setName(name+" Selector"+id);
|
||||
if (getSelectorPriorityDelta()!=0)
|
||||
Thread.currentThread().setPriority(Thread.currentThread().getPriority()+getSelectorPriorityDelta());
|
||||
LOG.debug("Starting {} on {}",Thread.currentThread(),this);
|
||||
while (isRunning())
|
||||
{
|
||||
try
|
||||
|
@ -293,6 +298,7 @@ public abstract class SelectorManager extends AbstractLifeCycle implements Dumpa
|
|||
}
|
||||
finally
|
||||
{
|
||||
LOG.debug("Stopped {} on {}",Thread.currentThread(),this);
|
||||
Thread.currentThread().setName(name);
|
||||
if (getSelectorPriorityDelta()!=0)
|
||||
Thread.currentThread().setPriority(priority);
|
||||
|
|
|
@ -52,7 +52,7 @@ import org.eclipse.jetty.util.log.Logger;
|
|||
*/
|
||||
public class JDBCSessionIdManager extends AbstractSessionIdManager
|
||||
{
|
||||
final static Logger __log = SessionHandler.__log;
|
||||
final static Logger LOG = SessionHandler.__log;
|
||||
|
||||
protected final HashSet<String> _sessionIds = new HashSet<String>();
|
||||
protected Server _server;
|
||||
|
@ -106,7 +106,7 @@ public class JDBCSessionIdManager extends AbstractSessionIdManager
|
|||
throws SQLException
|
||||
{
|
||||
_dbName = dbMeta.getDatabaseProductName().toLowerCase();
|
||||
__log.debug ("Using database "+_dbName);
|
||||
LOG.debug ("Using database "+_dbName);
|
||||
_isLower = dbMeta.storesLowerCaseIdentifiers();
|
||||
_isUpper = dbMeta.storesUpperCaseIdentifiers();
|
||||
}
|
||||
|
@ -230,7 +230,7 @@ public class JDBCSessionIdManager extends AbstractSessionIdManager
|
|||
if ((System.currentTimeMillis()%2) == 0)
|
||||
_scavengeIntervalMs += tenPercent;
|
||||
|
||||
if (__log.isDebugEnabled()) __log.debug("Scavenging every "+_scavengeIntervalMs+" ms");
|
||||
if (LOG.isDebugEnabled()) LOG.debug("Scavenging every "+_scavengeIntervalMs+" ms");
|
||||
if (_timer!=null && (period!=old_period || _task==null))
|
||||
{
|
||||
synchronized (this)
|
||||
|
@ -271,7 +271,7 @@ public class JDBCSessionIdManager extends AbstractSessionIdManager
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
__log.warn("Problem storing session id="+id, e);
|
||||
LOG.warn("Problem storing session id="+id, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -294,8 +294,8 @@ public class JDBCSessionIdManager extends AbstractSessionIdManager
|
|||
|
||||
synchronized (_sessionIds)
|
||||
{
|
||||
if (__log.isDebugEnabled())
|
||||
__log.debug("Removing session id="+id);
|
||||
if (LOG.isDebugEnabled())
|
||||
LOG.debug("Removing session id="+id);
|
||||
try
|
||||
{
|
||||
_sessionIds.remove(id);
|
||||
|
@ -303,7 +303,7 @@ public class JDBCSessionIdManager extends AbstractSessionIdManager
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
__log.warn("Problem removing session id="+id, e);
|
||||
LOG.warn("Problem removing session id="+id, e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -358,7 +358,7 @@ public class JDBCSessionIdManager extends AbstractSessionIdManager
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
__log.warn("Problem checking inUse for id="+clusterId, e);
|
||||
LOG.warn("Problem checking inUse for id="+clusterId, e);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -409,13 +409,13 @@ public class JDBCSessionIdManager extends AbstractSessionIdManager
|
|||
initializeDatabase();
|
||||
prepareTables();
|
||||
super.doStart();
|
||||
if (__log.isDebugEnabled()) __log.debug("Scavenging interval = "+getScavengeInterval()+" sec");
|
||||
if (LOG.isDebugEnabled()) LOG.debug("Scavenging interval = "+getScavengeInterval()+" sec");
|
||||
_timer=new Timer("JDBCSessionScavenger", true);
|
||||
setScavengeInterval(getScavengeInterval());
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
__log.warn("Problem initialising JettySessionIds table", e);
|
||||
LOG.warn("Problem initialising JettySessionIds table", e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -652,7 +652,7 @@ public class JDBCSessionIdManager extends AbstractSessionIdManager
|
|||
List<String> expiredSessionIds = new ArrayList<String>();
|
||||
try
|
||||
{
|
||||
if (__log.isDebugEnabled()) __log.debug("Scavenge sweep started at "+System.currentTimeMillis());
|
||||
if (LOG.isDebugEnabled()) LOG.debug("Scavenge sweep started at "+System.currentTimeMillis());
|
||||
if (_lastScavengeTime > 0)
|
||||
{
|
||||
connection = getConnection();
|
||||
|
@ -661,7 +661,7 @@ public class JDBCSessionIdManager extends AbstractSessionIdManager
|
|||
PreparedStatement statement = connection.prepareStatement(_selectExpiredSessions);
|
||||
long lowerBound = (_lastScavengeTime - _scavengeIntervalMs);
|
||||
long upperBound = _lastScavengeTime;
|
||||
if (__log.isDebugEnabled()) __log.debug (" Searching for sessions expired between "+lowerBound + " and "+upperBound);
|
||||
if (LOG.isDebugEnabled()) LOG.debug (" Searching for sessions expired between "+lowerBound + " and "+upperBound);
|
||||
|
||||
statement.setLong(1, lowerBound);
|
||||
statement.setLong(2, upperBound);
|
||||
|
@ -670,7 +670,7 @@ public class JDBCSessionIdManager extends AbstractSessionIdManager
|
|||
{
|
||||
String sessionId = result.getString("sessionId");
|
||||
expiredSessionIds.add(sessionId);
|
||||
if (__log.isDebugEnabled()) __log.debug (" Found expired sessionId="+sessionId);
|
||||
if (LOG.isDebugEnabled()) LOG.debug (" Found expired sessionId="+sessionId);
|
||||
}
|
||||
|
||||
//tell the SessionManagers to expire any sessions with a matching sessionId in memory
|
||||
|
@ -693,7 +693,7 @@ public class JDBCSessionIdManager extends AbstractSessionIdManager
|
|||
upperBound = _lastScavengeTime - (2 * _scavengeIntervalMs);
|
||||
if (upperBound > 0)
|
||||
{
|
||||
if (__log.isDebugEnabled()) __log.debug("Deleting old expired sessions expired before "+upperBound);
|
||||
if (LOG.isDebugEnabled()) LOG.debug("Deleting old expired sessions expired before "+upperBound);
|
||||
statement = connection.prepareStatement(_deleteOldExpiredSessions);
|
||||
statement.setLong(1, upperBound);
|
||||
statement.executeUpdate();
|
||||
|
@ -702,12 +702,15 @@ public class JDBCSessionIdManager extends AbstractSessionIdManager
|
|||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
__log.warn("Problem selecting expired sessions", e);
|
||||
if (isRunning())
|
||||
LOG.warn("Problem selecting expired sessions", e);
|
||||
else
|
||||
LOG.ignore(e);
|
||||
}
|
||||
finally
|
||||
{
|
||||
_lastScavengeTime=System.currentTimeMillis();
|
||||
if (__log.isDebugEnabled()) __log.debug("Scavenge sweep ended at "+_lastScavengeTime);
|
||||
if (LOG.isDebugEnabled()) LOG.debug("Scavenge sweep ended at "+_lastScavengeTime);
|
||||
if (connection != null)
|
||||
{
|
||||
try
|
||||
|
@ -716,7 +719,7 @@ public class JDBCSessionIdManager extends AbstractSessionIdManager
|
|||
}
|
||||
catch (SQLException e)
|
||||
{
|
||||
__log.warn(e);
|
||||
LOG.warn(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -155,7 +155,7 @@ public class HttpConnectionTest
|
|||
{
|
||||
try
|
||||
{
|
||||
((StdErrLog)Log.getLog()).setHideStacks(true);
|
||||
((StdErrLog)Log.getLogger(HttpConnection.class)).setHideStacks(true);
|
||||
|
||||
String response;
|
||||
|
||||
|
@ -186,7 +186,7 @@ public class HttpConnectionTest
|
|||
}
|
||||
finally
|
||||
{
|
||||
((StdErrLog)Log.getLog()).setHideStacks(false);
|
||||
((StdErrLog)Log.getLogger(HttpConnection.class)).setHideStacks(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -336,11 +336,7 @@ public class HttpConnectionTest
|
|||
Logger logger=null;
|
||||
try
|
||||
{
|
||||
if (!LOG.isDebugEnabled())
|
||||
{
|
||||
logger=Log.getLog();
|
||||
Log.setLog(null);
|
||||
}
|
||||
((StdErrLog)Log.getLogger(HttpConnection.class)).setHideStacks(true);
|
||||
response=connector.getResponses(requests);
|
||||
offset = checkContains(response,offset,"HTTP/1.1 500");
|
||||
offset = checkContains(response,offset,"Connection: close");
|
||||
|
@ -348,8 +344,7 @@ public class HttpConnectionTest
|
|||
}
|
||||
finally
|
||||
{
|
||||
if (logger!=null)
|
||||
Log.setLog(logger);
|
||||
((StdErrLog)Log.getLogger(HttpConnection.class)).setHideStacks(false);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -385,7 +385,6 @@ public class RFC2616Test
|
|||
String response;
|
||||
int offset=0;
|
||||
// Expect 100 not sent
|
||||
((StdErrLog)Log.getLog()).setHideStacks(true);
|
||||
offset=0;
|
||||
|
||||
response=connector.getResponses("GET /R1?error=401 HTTP/1.1\n"+
|
||||
|
@ -397,8 +396,6 @@ public class RFC2616Test
|
|||
checkNotContained(response,offset,"HTTP/1.1 100","8.2.3 expect 100");
|
||||
offset=checkContains(response,offset,"HTTP/1.1 401 ","8.2.3 expect 100")+1;
|
||||
offset=checkContains(response,offset,"Connection: close","8.2.3 expect 100")+1;
|
||||
|
||||
((StdErrLog)Log.getLog()).setHideStacks(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -38,7 +38,7 @@ import org.eclipse.jetty.util.Loader;
|
|||
public class Log
|
||||
{
|
||||
public final static String EXCEPTION= "EXCEPTION ";
|
||||
public final static String IGNORED= "IGNORED";
|
||||
public final static String IGNORED= "IGNORED ";
|
||||
|
||||
public static String __logClass;
|
||||
public static boolean __ignored;
|
||||
|
@ -233,10 +233,7 @@ public class Log
|
|||
{
|
||||
if (!initialized())
|
||||
return;
|
||||
if (__ignored)
|
||||
{
|
||||
__log.warn(IGNORED, thrown);
|
||||
}
|
||||
__log.ignore(thrown);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -309,7 +309,12 @@ public class StdErrLog implements Logger
|
|||
|
||||
private void format(StringBuilder builder, String msg, Object... args)
|
||||
{
|
||||
msg = String.valueOf(msg); // Avoids NPE
|
||||
if (msg==null)
|
||||
{
|
||||
msg="";
|
||||
for (Object o : args)
|
||||
msg+="{} ";
|
||||
}
|
||||
String braces = "{}";
|
||||
int start = 0;
|
||||
for (Object arg : args)
|
||||
|
@ -412,5 +417,9 @@ public class StdErrLog implements Logger
|
|||
{
|
||||
warn(Log.IGNORED, ignored);
|
||||
}
|
||||
else
|
||||
{
|
||||
debug("Ignored {}",ignored.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,11 +32,13 @@ public class LifeCycleListenerTest
|
|||
TestLifeCycle lifecycle = new TestLifeCycle();
|
||||
TestListener listener = new TestListener();
|
||||
lifecycle.addLifeCycleListener(listener);
|
||||
((StdErrLog)Log.getLog()).setHideStacks(true);
|
||||
|
||||
|
||||
lifecycle.setCause(cause);
|
||||
|
||||
|
||||
try
|
||||
{
|
||||
((StdErrLog)Log.getLogger(AbstractLifeCycle.class)).setHideStacks(true);
|
||||
lifecycle.start();
|
||||
assertTrue(false);
|
||||
}
|
||||
|
@ -45,10 +47,14 @@ public class LifeCycleListenerTest
|
|||
assertEquals(cause,e);
|
||||
assertEquals(cause,listener.getCause());
|
||||
}
|
||||
finally
|
||||
{
|
||||
((StdErrLog)Log.getLogger(AbstractLifeCycle.class)).setHideStacks(false);
|
||||
}
|
||||
lifecycle.setCause(null);
|
||||
((StdErrLog)Log.getLog()).setHideStacks(false);
|
||||
|
||||
|
||||
|
||||
|
||||
lifecycle.start();
|
||||
|
||||
// check that the starting event has been thrown
|
||||
|
@ -62,6 +68,7 @@ public class LifeCycleListenerTest
|
|||
|
||||
// check that the lifecycle's state is started
|
||||
assertTrue("The lifecycle state is not started",lifecycle.isStarted());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -77,12 +84,11 @@ public class LifeCycleListenerTest
|
|||
// stop() will return without doing anything
|
||||
|
||||
lifecycle.start();
|
||||
|
||||
((StdErrLog)Log.getLog()).setHideStacks(true);
|
||||
lifecycle.setCause(cause);
|
||||
|
||||
try
|
||||
{
|
||||
((StdErrLog)Log.getLogger(AbstractLifeCycle.class)).setHideStacks(true);
|
||||
lifecycle.stop();
|
||||
assertTrue(false);
|
||||
}
|
||||
|
@ -91,10 +97,12 @@ public class LifeCycleListenerTest
|
|||
assertEquals(cause,e);
|
||||
assertEquals(cause,listener.getCause());
|
||||
}
|
||||
finally
|
||||
{
|
||||
((StdErrLog)Log.getLogger(AbstractLifeCycle.class)).setHideStacks(false);
|
||||
}
|
||||
|
||||
|
||||
lifecycle.setCause(null);
|
||||
((StdErrLog)Log.getLog()).setHideStacks(false);
|
||||
|
||||
lifecycle.stop();
|
||||
|
||||
|
@ -117,22 +125,15 @@ public class LifeCycleListenerTest
|
|||
public void testRemoveLifecycleListener ()
|
||||
throws Exception
|
||||
{
|
||||
|
||||
|
||||
TestLifeCycle lifecycle = new TestLifeCycle();
|
||||
TestListener listener = new TestListener();
|
||||
lifecycle.addLifeCycleListener(listener);
|
||||
|
||||
lifecycle.start();
|
||||
((StdErrLog)Log.getLog()).setHideStacks(true);
|
||||
assertTrue("The starting event didn't occur",listener.starting);
|
||||
lifecycle.removeLifeCycleListener(listener);
|
||||
lifecycle.stop();
|
||||
assertFalse("The stopping event occurred", listener.stopping);
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
private class TestLifeCycle extends AbstractLifeCycle
|
||||
{
|
||||
|
|
|
@ -27,29 +27,32 @@ public class StdErrLogTest extends TestCase
|
|||
log.setHideStacks(true);
|
||||
|
||||
try {
|
||||
log.info("Testing info(msg,null,null) - {} {}","arg0","arg1");
|
||||
log.info("Testing info(msg,null,null) - {} {}",null,null);
|
||||
log.info("Testing info(msg,null,null) - {}",null,null);
|
||||
log.info("Testing info(msg,null,null)",null,null);
|
||||
log.info(null,"- Testing","info(null,arg0,arg1)");
|
||||
log.info(null,"Testing","info(null,arg0,arg1)");
|
||||
log.info(null,null,null);
|
||||
|
||||
log.debug("Testing debug(msg,null,null) - {} {}","arg0","arg1");
|
||||
log.debug("Testing debug(msg,null,null) - {} {}",null,null);
|
||||
log.debug("Testing debug(msg,null,null) - {}",null,null);
|
||||
log.debug("Testing debug(msg,null,null)",null,null);
|
||||
log.debug(null,"- Testing","debug(null,arg0,arg1)");
|
||||
log.debug(null,"Testing","debug(null,arg0,arg1)");
|
||||
log.debug(null,null,null);
|
||||
|
||||
log.debug("Testing debug(msg,null)");
|
||||
log.debug(null,new Throwable("IGNORE::Testing debug(null,thrw)").fillInStackTrace());
|
||||
log.debug(null,new Throwable("Testing debug(null,thrw)").fillInStackTrace());
|
||||
|
||||
log.warn("Testing warn(msg,null,null) - {} {}","arg0","arg1");
|
||||
log.warn("Testing warn(msg,null,null) - {} {}",null,null);
|
||||
log.warn("Testing warn(msg,null,null) - {}",null,null);
|
||||
log.warn("Testing warn(msg,null,null)",null,null);
|
||||
log.warn(null,"- Testing","warn(msg,arg0,arg1)");
|
||||
log.warn(null,"Testing","warn(msg,arg0,arg1)");
|
||||
log.warn(null,null,null);
|
||||
|
||||
log.warn("Testing warn(msg,null)");
|
||||
log.warn(null,new Throwable("IGNORE::Testing warn(msg,thrw)").fillInStackTrace());
|
||||
log.warn(null,new Throwable("Testing warn(msg,thrw)").fillInStackTrace());
|
||||
}
|
||||
catch (NullPointerException npe)
|
||||
{
|
||||
|
@ -58,4 +61,22 @@ public class StdErrLogTest extends TestCase
|
|||
assertTrue("NullPointerException in StdErrLog.", false);
|
||||
}
|
||||
}
|
||||
|
||||
public void testIgnores()
|
||||
{
|
||||
StdErrLog log = new StdErrLog(StdErrLogTest.class.getName());
|
||||
log.setHideStacks(true);
|
||||
|
||||
Log.__ignored=false;
|
||||
log.setDebugEnabled(false);
|
||||
log.ignore(new Throwable("IGNORE ME"));
|
||||
|
||||
Log.__ignored=true;
|
||||
log.setDebugEnabled(false);
|
||||
log.ignore(new Throwable("Don't ignore me"));
|
||||
|
||||
Log.__ignored=false;
|
||||
log.setDebugEnabled(true);
|
||||
log.ignore(new Throwable("Debug me"));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue