JETTY-1269 Improve log multithreadedness
git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@2257 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
parent
fa9a3fab2c
commit
2149d93443
|
@ -34,6 +34,7 @@ jetty-7.2-SNAPSHOT
|
|||
+ JETTY-1250 Parallel start of HandlerCollection
|
||||
+ JETTY-1256 annotation jars from Orbit
|
||||
+ JETTY-1261 errant listener usage in StandardDescriptorProcessor
|
||||
+ JETTY-1269 Improve log multithreadedness
|
||||
+ JETTY-1271 handled unavailable exception
|
||||
+ Fix jetty-plus.xml for new configuration names
|
||||
+ Added ignore to Logger interface
|
||||
|
|
|
@ -68,8 +68,6 @@ public class NCSARequestLog extends AbstractLifeCycle implements RequestLog
|
|||
private transient DateCache _logDateCache;
|
||||
private transient PathMap _ignorePathMap;
|
||||
private transient Writer _writer;
|
||||
private transient ArrayList _buffers;
|
||||
private transient char[] _copy;
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
|
@ -448,9 +446,6 @@ public class NCSARequestLog extends AbstractLifeCycle implements RequestLog
|
|||
*/
|
||||
public void log(Request request, Response response)
|
||||
{
|
||||
if (!isStarted())
|
||||
return;
|
||||
|
||||
try
|
||||
{
|
||||
if (_ignorePathMap != null && _ignorePathMap.getMatch(request.getRequestURI()) != null)
|
||||
|
@ -459,14 +454,7 @@ public class NCSARequestLog extends AbstractLifeCycle implements RequestLog
|
|||
if (_fileOut == null)
|
||||
return;
|
||||
|
||||
Utf8StringBuilder u8buf;
|
||||
StringBuilder buf;
|
||||
synchronized(_writer)
|
||||
{
|
||||
int size=_buffers.size();
|
||||
u8buf = size==0?new Utf8StringBuilder(160):(Utf8StringBuilder)_buffers.remove(size-1);
|
||||
buf = u8buf.getStringBuilder();
|
||||
}
|
||||
StringBuilder buf= new StringBuilder(256);
|
||||
|
||||
if (_logServer)
|
||||
{
|
||||
|
@ -500,9 +488,7 @@ public class NCSARequestLog extends AbstractLifeCycle implements RequestLog
|
|||
buf.append("] \"");
|
||||
buf.append(request.getMethod());
|
||||
buf.append(' ');
|
||||
|
||||
request.getUri().writeTo(u8buf);
|
||||
|
||||
buf.append(request.getUri().toString());
|
||||
buf.append(' ');
|
||||
buf.append(request.getProtocol());
|
||||
buf.append("\" ");
|
||||
|
@ -541,78 +527,58 @@ public class NCSARequestLog extends AbstractLifeCycle implements RequestLog
|
|||
else
|
||||
buf.append(" - ");
|
||||
|
||||
if (!_extended && !_logCookies && !_logLatency)
|
||||
{
|
||||
synchronized(_writer)
|
||||
{
|
||||
buf.append(StringUtil.__LINE_SEPARATOR);
|
||||
int l=buf.length();
|
||||
if (l>_copy.length)
|
||||
l=_copy.length;
|
||||
buf.getChars(0,l,_copy,0);
|
||||
_writer.write(_copy,0,l);
|
||||
_writer.flush();
|
||||
u8buf.reset();
|
||||
_buffers.add(u8buf);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
synchronized(_writer)
|
||||
{
|
||||
int l=buf.length();
|
||||
if (l>_copy.length)
|
||||
l=_copy.length;
|
||||
buf.getChars(0,l,_copy,0);
|
||||
_writer.write(_copy,0,l);
|
||||
u8buf.reset();
|
||||
_buffers.add(u8buf);
|
||||
|
||||
// TODO do outside synchronized scope
|
||||
if (_extended)
|
||||
logExtended(request, response, _writer);
|
||||
logExtended(request, response, buf);
|
||||
|
||||
// TODO do outside synchronized scope
|
||||
if (_logCookies)
|
||||
{
|
||||
Cookie[] cookies = request.getCookies();
|
||||
if (cookies == null || cookies.length == 0)
|
||||
_writer.write(" -");
|
||||
buf.append(" -");
|
||||
else
|
||||
{
|
||||
_writer.write(" \"");
|
||||
buf.append(" \"");
|
||||
for (int i = 0; i < cookies.length; i++)
|
||||
{
|
||||
if (i != 0)
|
||||
_writer.write(';');
|
||||
_writer.write(cookies[i].getName());
|
||||
_writer.write('=');
|
||||
_writer.write(cookies[i].getValue());
|
||||
buf.append(';');
|
||||
buf.append(cookies[i].getName());
|
||||
buf.append('=');
|
||||
buf.append(cookies[i].getValue());
|
||||
}
|
||||
_writer.write('\"');
|
||||
buf.append('\"');
|
||||
}
|
||||
}
|
||||
|
||||
final long now = System.currentTimeMillis();
|
||||
final long start = request.getTimeStamp();
|
||||
final long dispatch = request.getDispatchTime();
|
||||
if (_logDispatch || _logLatency)
|
||||
{
|
||||
long now = System.currentTimeMillis();
|
||||
|
||||
if (_logDispatch)
|
||||
{
|
||||
_writer.write(' ');
|
||||
_writer.write(Long.toString(now - (dispatch==0 ? start:dispatch)));
|
||||
long d = request.getDispatchTime();
|
||||
buf.append(' ');
|
||||
buf.append(now - (d==0 ? request.getTimeStamp():d));
|
||||
}
|
||||
|
||||
if (_logLatency)
|
||||
{
|
||||
_writer.write(' ');
|
||||
_writer.write(Long.toString(now - start));
|
||||
buf.append(' ');
|
||||
buf.append(now - request.getTimeStamp());
|
||||
}
|
||||
}
|
||||
|
||||
_writer.write(StringUtil.__LINE_SEPARATOR);
|
||||
buf.append(StringUtil.__LINE_SEPARATOR);
|
||||
String log = buf.toString();
|
||||
synchronized(this)
|
||||
{
|
||||
if (_writer==null)
|
||||
return;
|
||||
_writer.write(log);
|
||||
_writer.flush();
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
Log.warn(e);
|
||||
|
@ -626,31 +592,31 @@ public class NCSARequestLog extends AbstractLifeCycle implements RequestLog
|
|||
*
|
||||
* @param request request object
|
||||
* @param response response object
|
||||
* @param writer log file writer
|
||||
* @param b StringBuilder to write to
|
||||
* @throws IOException
|
||||
*/
|
||||
protected void logExtended(Request request,
|
||||
Response response,
|
||||
Writer writer) throws IOException
|
||||
StringBuilder b) throws IOException
|
||||
{
|
||||
String referer = request.getHeader(HttpHeaders.REFERER);
|
||||
if (referer == null)
|
||||
writer.write("\"-\" ");
|
||||
b.append("\"-\" ");
|
||||
else
|
||||
{
|
||||
writer.write('"');
|
||||
writer.write(referer);
|
||||
writer.write("\" ");
|
||||
b.append('"');
|
||||
b.append(referer);
|
||||
b.append("\" ");
|
||||
}
|
||||
|
||||
String agent = request.getHeader(HttpHeaders.USER_AGENT);
|
||||
if (agent == null)
|
||||
writer.write("\"-\" ");
|
||||
b.append("\"-\" ");
|
||||
else
|
||||
{
|
||||
writer.write('"');
|
||||
writer.write(agent);
|
||||
writer.write('"');
|
||||
b.append('"');
|
||||
b.append(agent);
|
||||
b.append('"');
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -690,8 +656,6 @@ public class NCSARequestLog extends AbstractLifeCycle implements RequestLog
|
|||
_ignorePathMap = null;
|
||||
|
||||
_writer = new OutputStreamWriter(_out);
|
||||
_buffers = new ArrayList();
|
||||
_copy = new char[1024];
|
||||
super.doStart();
|
||||
}
|
||||
|
||||
|
@ -703,6 +667,8 @@ public class NCSARequestLog extends AbstractLifeCycle implements RequestLog
|
|||
*/
|
||||
@Override
|
||||
protected void doStop() throws Exception
|
||||
{
|
||||
synchronized (this)
|
||||
{
|
||||
super.doStop();
|
||||
try
|
||||
|
@ -729,7 +695,6 @@ public class NCSARequestLog extends AbstractLifeCycle implements RequestLog
|
|||
_closeOut = false;
|
||||
_logDateCache = null;
|
||||
_writer = null;
|
||||
_buffers = null;
|
||||
_copy = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue