Package org.eclipse.jetty.server
Class AbstractNCSARequestLog
- java.lang.Object
-
- org.eclipse.jetty.util.component.AbstractLifeCycle
-
- org.eclipse.jetty.server.AbstractNCSARequestLog
-
- All Implemented Interfaces:
RequestLog,org.eclipse.jetty.util.component.LifeCycle
- Direct Known Subclasses:
NCSARequestLog,Slf4jRequestLog
public abstract class AbstractNCSARequestLog extends org.eclipse.jetty.util.component.AbstractLifeCycle implements RequestLog
Base implementation of theRequestLogoutputs logs in the pseudo-standard NCSA common log format. Configuration options allow a choice between the standard Common Log Format (as used in the 3 log format) and the Combined Log Format (single log format). This log format can be output by most web servers, and almost all web log analysis software can understand these formats.
-
-
Field Summary
Fields Modifier and Type Field Description protected static org.eclipse.jetty.util.log.LoggerLOG
-
Constructor Summary
Constructors Constructor Description AbstractNCSARequestLog()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Deprecated Methods Modifier and Type Method Description protected voiddoStart()Set up request logging and open log file.protected voiddoStop()protected StringgetAuthentication(Request request)Extract the user authenticationString[]getIgnorePaths()Retrieve the request paths that will not be logged.booleangetLogCookies()Retrieve log cookies flagStringgetLogDateFormat()Retrieve the timestamp format string for request log entries.booleangetLogLatency()Retrieve log request processing time flag.LocalegetLogLocale()Retrieve the locale of the request log.booleangetLogServer()Retrieve log hostname flag.StringgetLogTimeZone()Retrieve the timezone of the request log.booleangetPreferProxiedForAddress()Retrieved log X-Forwarded-For IP address flag.protected abstract booleanisEnabled()Is logging enabledbooleanisExtended()Retrieve the extended request log format flag.booleanisLogDispatch()Deprecated.voidlog(Request request, Response response)Writes the request and response information to the output stream.protected voidlogExtended(StringBuilder b, Request request, Response response)Writes extended request and response information to the output stream.voidsetExtended(boolean extended)Set the extended request log format flag.voidsetIgnorePaths(String[] ignorePaths)Set request paths that will not be logged.voidsetLogCookies(boolean logCookies)Controls logging of the request cookies.voidsetLogDateFormat(String format)Set the timestamp format for request log entries in the file.voidsetLogDispatch(boolean value)Deprecated.voidsetLogLatency(boolean logLatency)Controls logging of request processing time.voidsetLogLocale(Locale logLocale)Set the locale of the request log.voidsetLogServer(boolean logServer)Controls logging of the request hostname.voidsetLogTimeZone(String tz)Set the timezone of the request log.voidsetPreferProxiedForAddress(boolean preferProxiedForAddress)Controls whether the actual IP address of the connection or the IP address from the X-Forwarded-For header will be logged.abstract voidwrite(String requestEntry)Write requestEntry out.
-
-
-
Method Detail
-
isEnabled
protected abstract boolean isEnabled()
Is logging enabled- Returns:
- true if logging is enabled
-
write
public abstract void write(String requestEntry) throws IOException
Write requestEntry out. (to disk or slf4j log)- Parameters:
requestEntry- the request entry- Throws:
IOException- if unable to write the entry
-
log
public void log(Request request, Response response)
Writes the request and response information to the output stream.- Specified by:
login interfaceRequestLog- Parameters:
request- The request to log.response- The response to log. Note that for some requests the response instance may not have been fully populated (Eg 400 bad request responses are sent without a servlet response object). Thus for basic log information it is best to consultResponse.getCommittedMetaData()andResponse.getHttpChannel()directly.- See Also:
RequestLog.log(Request, Response)
-
getAuthentication
protected String getAuthentication(Request request)
Extract the user authentication- Parameters:
request- The request to extract from- Returns:
- The string to log for authenticated user.
-
logExtended
protected void logExtended(StringBuilder b, Request request, Response response) throws IOException
Writes extended request and response information to the output stream.- Parameters:
b- StringBuilder to write torequest- request objectresponse- response object- Throws:
IOException- if unable to log the extended information
-
setIgnorePaths
public void setIgnorePaths(String[] ignorePaths)
Set request paths that will not be logged.- Parameters:
ignorePaths- array of request paths
-
getIgnorePaths
public String[] getIgnorePaths()
Retrieve the request paths that will not be logged.- Returns:
- array of request paths
-
setLogCookies
public void setLogCookies(boolean logCookies)
Controls logging of the request cookies.- Parameters:
logCookies- true - values of request cookies will be logged, false - values of request cookies will not be logged
-
getLogCookies
public boolean getLogCookies()
Retrieve log cookies flag- Returns:
- value of the flag
-
setLogServer
public void setLogServer(boolean logServer)
Controls logging of the request hostname.- Parameters:
logServer- true - request hostname will be logged, false - request hostname will not be logged
-
getLogServer
public boolean getLogServer()
Retrieve log hostname flag.- Returns:
- value of the flag
-
setLogLatency
public void setLogLatency(boolean logLatency)
Controls logging of request processing time.- Parameters:
logLatency- true - request processing time will be logged false - request processing time will not be logged
-
getLogLatency
public boolean getLogLatency()
Retrieve log request processing time flag.- Returns:
- value of the flag
-
setLogDispatch
@Deprecated public void setLogDispatch(boolean value)
Deprecated.- Parameters:
value- true to log dispatch
-
isLogDispatch
@Deprecated public boolean isLogDispatch()
Deprecated.- Returns:
- true if logging dispatches
-
setPreferProxiedForAddress
public void setPreferProxiedForAddress(boolean preferProxiedForAddress)
Controls whether the actual IP address of the connection or the IP address from the X-Forwarded-For header will be logged.- Parameters:
preferProxiedForAddress- true - IP address from header will be logged, false - IP address from the connection will be logged
-
getPreferProxiedForAddress
public boolean getPreferProxiedForAddress()
Retrieved log X-Forwarded-For IP address flag.- Returns:
- value of the flag
-
setExtended
public void setExtended(boolean extended)
Set the extended request log format flag.- Parameters:
extended- true - log the extended request information, false - do not log the extended request information
-
isExtended
@ManagedAttribute("use extended NCSA format") public boolean isExtended()Retrieve the extended request log format flag.- Returns:
- value of the flag
-
doStart
protected void doStart() throws ExceptionSet up request logging and open log file.- Overrides:
doStartin classorg.eclipse.jetty.util.component.AbstractLifeCycle- Throws:
Exception- See Also:
AbstractLifeCycle.doStart()
-
doStop
protected void doStop() throws Exception- Overrides:
doStopin classorg.eclipse.jetty.util.component.AbstractLifeCycle- Throws:
Exception
-
setLogDateFormat
public void setLogDateFormat(String format)
Set the timestamp format for request log entries in the file. If this is not set, the pre-formated request timestamp is used.- Parameters:
format- timestamp format string
-
getLogDateFormat
public String getLogDateFormat()
Retrieve the timestamp format string for request log entries.- Returns:
- timestamp format string.
-
setLogLocale
public void setLogLocale(Locale logLocale)
Set the locale of the request log.- Parameters:
logLocale- locale object
-
getLogLocale
public Locale getLogLocale()
Retrieve the locale of the request log.- Returns:
- locale object
-
setLogTimeZone
public void setLogTimeZone(String tz)
Set the timezone of the request log.- Parameters:
tz- timezone string
-
getLogTimeZone
@ManagedAttribute("the timezone") public String getLogTimeZone()Retrieve the timezone of the request log.- Returns:
- timezone string
-
-