diff options
Diffstat (limited to 'jetty-server/src/main/java/org/eclipse/jetty/server/AbstractNCSARequestLog.java')
-rw-r--r-- | jetty-server/src/main/java/org/eclipse/jetty/server/AbstractNCSARequestLog.java | 82 |
1 files changed, 48 insertions, 34 deletions
diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractNCSARequestLog.java b/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractNCSARequestLog.java index a9ac0d6518..ab46bd5217 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractNCSARequestLog.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/AbstractNCSARequestLog.java @@ -25,6 +25,7 @@ import javax.servlet.http.Cookie; import org.eclipse.jetty.http.HttpHeader; import org.eclipse.jetty.http.PathMap; +import org.eclipse.jetty.server.handler.StatisticsHandler; import org.eclipse.jetty.util.DateCache; import org.eclipse.jetty.util.annotation.ManagedAttribute; import org.eclipse.jetty.util.component.AbstractLifeCycle; @@ -67,6 +68,7 @@ public abstract class AbstractNCSARequestLog extends AbstractLifeCycle implement /** * Is logging enabled + * @return true if logging is enabled */ protected abstract boolean isEnabled(); @@ -74,22 +76,34 @@ public abstract class AbstractNCSARequestLog extends AbstractLifeCycle implement /** * Write requestEntry out. (to disk or slf4j log) + * @param requestEntry the request entry + * @throws IOException if unable to write the entry */ public abstract void write(String requestEntry) throws IOException; /* ------------------------------------------------------------ */ - + + private void append(StringBuilder buf,String s) + { + if (s==null || s.length()==0) + buf.append('-'); + else + buf.append(s); + } + /** * Writes the request and response information to the output stream. * - * @see org.eclipse.jetty.server.RequestLog#log(org.eclipse.jetty.server.Request, - * org.eclipse.jetty.server.Response) + * @see org.eclipse.jetty.server.RequestLog#log(Request, Response) */ @Override public void log(Request request, Response response) { try { + int status = response.getCommittedMetaData().getStatus(); + long written = response.getHttpChannel().getBytesWritten(); + if (_ignorePathMap != null && _ignorePathMap.getMatch(request.getRequestURI()) != null) return; @@ -101,7 +115,7 @@ public abstract class AbstractNCSARequestLog extends AbstractLifeCycle implement if (_logServer) { - buf.append(request.getServerName()); + append(buf,request.getServerName()); buf.append(' '); } @@ -117,10 +131,7 @@ public abstract class AbstractNCSARequestLog extends AbstractLifeCycle implement buf.append(addr); buf.append(" - "); Authentication authentication = request.getAuthentication(); - if (authentication instanceof Authentication.User) - buf.append(((Authentication.User)authentication).getUserIdentity().getUserPrincipal().getName()); - else - buf.append("-"); + append(buf,(authentication instanceof Authentication.User)?((Authentication.User)authentication).getUserIdentity().getUserPrincipal().getName():null); buf.append(" ["); if (_logDateCache != null) @@ -129,37 +140,38 @@ public abstract class AbstractNCSARequestLog extends AbstractLifeCycle implement buf.append(request.getTimeStamp()); buf.append("] \""); - buf.append(request.getMethod()); + append(buf,request.getMethod()); buf.append(' '); - buf.append(request.getUri().toString()); + append(buf,request.getHttpURI().toString()); buf.append(' '); - buf.append(request.getProtocol()); + append(buf,request.getProtocol()); buf.append("\" "); - int status = response.getStatus(); - if (status <= 0) - status = 404; - buf.append((char)('0' + ((status / 100) % 10))); - buf.append((char)('0' + ((status / 10) % 10))); - buf.append((char)('0' + (status % 10))); + if (status >=0) + { + buf.append((char)('0' + ((status / 100) % 10))); + buf.append((char)('0' + ((status / 10) % 10))); + buf.append((char)('0' + (status % 10))); + } + else + buf.append(status); - long responseLength = response.getLongContentLength(); - if (responseLength >= 0) + if (written >= 0) { buf.append(' '); - if (responseLength > 99999) - buf.append(responseLength); + if (written > 99999) + buf.append(written); else { - if (responseLength > 9999) - buf.append((char)('0' + ((responseLength / 10000) % 10))); - if (responseLength > 999) - buf.append((char)('0' + ((responseLength / 1000) % 10))); - if (responseLength > 99) - buf.append((char)('0' + ((responseLength / 100) % 10))); - if (responseLength > 9) - buf.append((char)('0' + ((responseLength / 10) % 10))); - buf.append((char)('0' + (responseLength) % 10)); + if (written > 9999) + buf.append((char)('0' + ((written / 10000) % 10))); + if (written > 999) + buf.append((char)('0' + ((written / 1000) % 10))); + if (written > 99) + buf.append((char)('0' + ((written / 100) % 10))); + if (written > 9) + buf.append((char)('0' + ((written / 10) % 10))); + buf.append((char)('0' + (written) % 10)); } buf.append(' '); } @@ -168,7 +180,7 @@ public abstract class AbstractNCSARequestLog extends AbstractLifeCycle implement if (_extended) - logExtended(request, response, buf); + logExtended(request, buf); if (_logCookies) { @@ -216,12 +228,10 @@ public abstract class AbstractNCSARequestLog extends AbstractLifeCycle implement * Writes extended request and response information to the output stream. * * @param request request object - * @param response response object * @param b StringBuilder to write to - * @throws IOException + * @throws IOException if unable to log the extended information */ protected void logExtended(Request request, - Response response, StringBuilder b) throws IOException { String referer = request.getHeader(HttpHeader.REFERER.toString()); @@ -329,15 +339,19 @@ public abstract class AbstractNCSARequestLog extends AbstractLifeCycle implement } /** + * @param value true to log dispatch * @deprecated use {@link StatisticsHandler} */ + @Deprecated public void setLogDispatch(boolean value) { } /** + * @return true if logging dispatches * @deprecated use {@link StatisticsHandler} */ + @Deprecated public boolean isLogDispatch() { return false; |