Class ExtendedAccessLogValve
- java.lang.Object
-
- org.apache.catalina.valves.ValveBase
-
- org.apache.catalina.valves.ExtendedAccessLogValve
-
- All Implemented Interfaces:
Contained
,Lifecycle
,Valve
,GlassFishValve
public final class ExtendedAccessLogValve extends ValveBase
An implementation of the W3c Extended Log File Format. See http://www.w3.org/TR/WD-logfile.html for more information about the format. The following fields are supported:c-dns
: Client hostnamec-ip
: Client ip addressbytes
: bytes servedcs-method
: request methodcs-uri
: The full uri requestedcs-uri-query
: The query stringcs-uri-stem
: The uri without query stringdate
: The date in yyyy-mm-dd format for GMTs-dns
: The server dns entrys-ip
: The server ip addresscs(XXX)
: The value of header XXX from client to serversc(XXX)
: The value of header XXX from server to clientsc-status
: The status codetime
: Time the request was servedtime-taken
: Time (in seconds) taken to serve the requestx-A(XXX)
: Pull XXX attribute from the servlet contextx-C(XXX)
: Pull the first cookie of the name XXXx-R(XXX)
: Pull XXX attribute from the servlet requestx-S(XXX)
: Pull XXX attribute from the sessionx-P(...)
: Call request.getParameter(...) and URLencode it. Helpful to capture certain POST parameters.- For any of the x-H(...) the following method will be called from the HttpServletRequestObject
x-H(authType)
: getAuthTypex-H(characterEncoding)
: getCharacterEncodingx-H(contentLength)
: getContentLengthx-H(locale)
: getLocalex-H(protocol)
: getProtocolx-H(remoteUser)
: getRemoteUserx-H(requestedSessionId)
: getGequestedSessionIdx-H(requestedSessionIdFromCookie)
: isRequestedSessionIdFromCookiex-H(requestedSessionIdValid)
: isRequestedSessionIdValidx-H(scheme)
: getSchemex-H(secure)
: isSecure
Log rotation can be on or off. This is dictated by the rotatable property.
For UNIX users, another field called
checkExists
is also available. If set to true, the log file's existence will be checked before each logging. This way an external log rotator can move the file somewhere and tomcat will start with a new file.For JMX junkies, a public method called rotate has been made available to allow you to tell this instance to move the existing log file to somewhere else start writing a new log file.
Conditional logging is also supported. This can be done with the
condition
property. If the value returned from ServletRequest.getAttribute(condition) yields a non-null value. The logging will be skipped.For extended attributes coming from a getAttribute() call, it is you responsibility to ensure there are no newline or control characters.
- Version:
- $Revision: 1.4 $ $Date: 2006/04/17 16:44:48 $
- Author:
- Tim Funk
-
-
Field Summary
-
Fields inherited from class org.apache.catalina.valves.ValveBase
container, controller, debug, domain, lifecycle, log, next, oname, rb, started
-
Fields inherited from interface org.glassfish.web.valve.GlassFishValve
END_PIPELINE, INVOKE_NEXT
-
Fields inherited from interface org.apache.catalina.Lifecycle
AFTER_START_EVENT, AFTER_STOP_EVENT, BEFORE_START_EVENT, BEFORE_STOP_EVENT, INIT_EVENT, START_EVENT, STOP_EVENT
-
-
Constructor Summary
Constructors Constructor Description ExtendedAccessLogValve()
Construct a new instance of this class with default property values.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.apache.catalina.valves.FieldInfo[]
decodePattern(String fields)
Decode the given pattern.String
getCondition()
Return whether the attribute name to look for when performing conditional loggging.String
getDirectory()
Return the directory in which we create log files.String
getFileDateFormat()
Return the date format date based log rotation.String
getInfo()
Return descriptive information about this implementation.String
getPattern()
Return the format pattern.String
getPrefix()
Return the log file prefix.String
getSuffix()
Return the log file suffix.int
invoke(Request request, Response response)
Log a message summarizing the specified request and response, according to the format specified by thepattern
property.boolean
isCheckExists()
Check for file existence before logging.boolean
isRotatable()
Return true if logs are automatically rotated.void
postInvoke(Request request, Response response)
A post-request processing implementation that does nothing.boolean
rotate(String newFileName)
Rename the existing log file to something else.void
setCheckExists(boolean checkExists)
Set whether to check for log file existence before logging.void
setCondition(String condition)
Set the ServletRequest.attribute to look for to perform conditional logging.void
setDirectory(String directory)
Set the directory in which we create log files.void
setFileDateFormat(String fileDateFormat)
Set the date format date based log rotation.void
setPattern(String pattern)
Set the format pattern, first translating any recognized alias.void
setPrefix(String prefix)
Set the log file prefix.void
setRotatable(boolean rotatable)
Set the value is we should we rotate the logsvoid
setSuffix(String suffix)
Set the log file suffix.void
start()
Prepare for the beginning of active use of the public methods of this component.void
stop()
Gracefully terminate the active use of the public methods of this component.-
Methods inherited from class org.apache.catalina.valves.ValveBase
addLifecycleListener, backgroundProcess, createObjectName, event, findLifecycleListeners, getContainer, getController, getDebug, getDomain, getNext, getObjectName, getParentName, invoke, isStarted, removeLifecycleListener, setContainer, setController, setDebug, setNext, setObjectName
-
-
-
-
Method Detail
-
getDirectory
public String getDirectory()
Return the directory in which we create log files.
-
setDirectory
public void setDirectory(String directory)
Set the directory in which we create log files.- Parameters:
directory
- The new log file directory
-
getInfo
public String getInfo()
Return descriptive information about this implementation.
-
getPattern
public String getPattern()
Return the format pattern.
-
setPattern
public void setPattern(String pattern)
Set the format pattern, first translating any recognized alias.- Parameters:
pattern
- The new pattern pattern
-
getPrefix
public String getPrefix()
Return the log file prefix.
-
setPrefix
public void setPrefix(String prefix)
Set the log file prefix.- Parameters:
prefix
- The new log file prefix
-
isRotatable
public boolean isRotatable()
Return true if logs are automatically rotated.
-
setRotatable
public void setRotatable(boolean rotatable)
Set the value is we should we rotate the logs- Parameters:
rotatable
- true is we should rotate.
-
getSuffix
public String getSuffix()
Return the log file suffix.
-
setSuffix
public void setSuffix(String suffix)
Set the log file suffix.- Parameters:
suffix
- The new log file suffix
-
getCondition
public String getCondition()
Return whether the attribute name to look for when performing conditional loggging. If null, every request is logged.
-
setCondition
public void setCondition(String condition)
Set the ServletRequest.attribute to look for to perform conditional logging. Set to null to log everything.- Parameters:
condition
- Set to null to log everything
-
isCheckExists
public boolean isCheckExists()
Check for file existence before logging.
-
setCheckExists
public void setCheckExists(boolean checkExists)
Set whether to check for log file existence before logging.- Parameters:
checkExists
- true meaning to check for file existence.
-
getFileDateFormat
public String getFileDateFormat()
Return the date format date based log rotation.
-
setFileDateFormat
public void setFileDateFormat(String fileDateFormat)
Set the date format date based log rotation.
-
invoke
public int invoke(Request request, Response response) throws IOException, jakarta.servlet.ServletException
Log a message summarizing the specified request and response, according to the format specified by thepattern
property.- Specified by:
invoke
in interfaceGlassFishValve
- Specified by:
invoke
in classValveBase
- Parameters:
request
- Request being processedresponse
- Response being processed- Returns:
INVOKE_NEXT
orEND_PIPELINE
- Throws:
IOException
- if an input/output error has occurredjakarta.servlet.ServletException
- if a servlet error has occurred
-
postInvoke
public void postInvoke(Request request, Response response) throws IOException, jakarta.servlet.ServletException
Description copied from class:ValveBase
A post-request processing implementation that does nothing. Very few Valves override this behaviour as most Valve logic is used for request processing.- Specified by:
postInvoke
in interfaceGlassFishValve
- Overrides:
postInvoke
in classValveBase
- Parameters:
request
- The servlet request to be processedresponse
- The servlet response to be created- Throws:
IOException
- if an input/output error occursjakarta.servlet.ServletException
- if a servlet error occurs
-
rotate
public boolean rotate(String newFileName)
Rename the existing log file to something else. Then open the old log file name up once again. Intended to be called by a JMX agent.- Parameters:
newFileName
- The file name to move the log file entry to- Returns:
- true if a file was rotated with no error
-
start
public void start() throws LifecycleException
Prepare for the beginning of active use of the public methods of this component. This method should be called afterconfigure()
, and before any of the public methods of the component are utilized.- Specified by:
start
in interfaceLifecycle
- Overrides:
start
in classValveBase
- Throws:
LifecycleException
- if this component detects a fatal error that prevents this component from being used
-
stop
public void stop() throws LifecycleException
Gracefully terminate the active use of the public methods of this component. This method should be the last one called on a given instance of this component.- Specified by:
stop
in interfaceLifecycle
- Overrides:
stop
in classValveBase
- Throws:
LifecycleException
- if this component detects a fatal error that needs to be reported
-
decodePattern
public org.apache.catalina.valves.FieldInfo[] decodePattern(String fields)
Decode the given pattern. Is public so a pattern may allows to be validated.- Parameters:
fields
- The pattern to decode- Returns:
- null on error. Otherwise array of decoded fields
-
-