|
|||||||||
| Home >> All >> org >> apache >> catalina >> [ valves overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
org.apache.catalina.valves
Class AccessLogValve

java.lang.Objectorg.apache.catalina.valves.ValveBase
org.apache.catalina.valves.AccessLogValve
- All Implemented Interfaces:
- org.apache.catalina.Contained, org.apache.catalina.Lifecycle, javax.management.MBeanRegistration, org.apache.catalina.Valve
- public class AccessLogValve
- extends ValveBase
- implements org.apache.catalina.Lifecycle
- extends ValveBase
Implementation of the Valve interface that generates a web server
access log with the detailed line contents matching a configurable pattern.
The syntax of the available patterns is similar to that supported by the
Apache mod_log_config module. As an additional feature,
automatic rollover of log files when the date changes is also supported.
Patterns for the logged message may include constant text or any of the following replacement strings, for which the corresponding information from the specified Response is substituted:
- %a - Remote IP address
- %A - Local IP address
- %b - Bytes sent, excluding HTTP headers, or '-' if no bytes were sent
- %B - Bytes sent, excluding HTTP headers
- %h - Remote host name
- %H - Request protocol
- %l - Remote logical username from identd (always returns '-')
- %m - Request method
- %p - Local port
- %q - Query string (prepended with a '?' if it exists, otherwise an empty string
- %r - First line of the request
- %s - HTTP status code of the response
- %S - User session ID
- %t - Date and time, in Common Log Format format
- %u - Remote user that was authenticated
- %U - Requested URL path
- %v - Local server name
- %D - Time taken to process the request, in millis
- %T - Time taken to process the request, in seconds
In addition, the caller can specify one of the following aliases for commonly utilized patterns:
- common -
%h %l %u %t "%r" %s %b - combined -
%h %l %u %t "%r" %s %b "%{Referer}i" "%{User-Agent}i"
There is also support to write information from the cookie, incoming
header, the Session or something else in the ServletRequest.
It is modeled after the apache syntax:
%{xxx}ifor incoming headers%{xxx}cfor a specific cookie%{xxx}rxxx is an attribute in the ServletRequest%{xxx}sxxx is an attribute in the HttpSession
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.
- Version:
- $Revision: 303826 $ $Date: 2005-03-31 05:31:54 -0500 (Thu, 31 Mar 2005) $
| Field Summary | |
private boolean |
combined
For the combined format (common, plus useragent and referer), we do the same |
private boolean |
common
If the current log pattern is the same as the common access log format pattern, then we'll set this variable to true and log in a more optimal and hard-coded way. |
private java.lang.String |
condition
Are we doing conditional logging. |
private java.util.Date |
currentDate
The system time when we last updated the Date that this valve uses for log lines. |
private java.text.SimpleDateFormat |
dateFormatter
A date formatter to format a Date into a date in the format "yyyy-MM-dd". |
private java.lang.String |
dateStamp
The as-of date for the currently open log file, or a zero-length string if there is no open log file. |
private java.text.SimpleDateFormat |
dayFormatter
A date formatter to format Dates into a day string in the format "dd". |
private java.lang.String |
directory
The directory in which log files are created. |
private java.lang.String |
fileDateFormat
Date format to place in log file name. |
protected static java.lang.String |
info
The descriptive information about this implementation. |
protected org.apache.catalina.util.LifecycleSupport |
lifecycle
The lifecycle event support for this component. |
private java.text.SimpleDateFormat |
monthFormatter
A date formatter to format a Date into a month string in the format "MM". |
protected static java.lang.String[] |
months
The set of month abbreviations for log messages. |
private java.lang.String |
pattern
The pattern used to format our access log lines. |
private java.lang.String |
prefix
The prefix that is added to log file filenames. |
private boolean |
resolveHosts
Resolve hosts. |
private boolean |
rotatable
Should we rotate our log file? Default is true (like old behavior) |
private long |
rotationLastChecked
Instant when the log daily rotation was last checked. |
private org.apache.catalina.util.StringManager |
sm
The string manager for this package. |
private java.lang.String |
space
When formatting log lines, we often use strings like this one (" "). |
private boolean |
started
Has this component been started yet? |
private java.lang.String |
suffix
The suffix that is added to log file filenames. |
private java.text.SimpleDateFormat |
timeFormatter
A date formatter to format a Date into a time in the format "kk:mm:ss" (kk is a 24-hour representation of the hour). |
private java.text.DecimalFormat |
timeTakenFormatter
Time taken formatter for 3 decimal places. |
private java.util.TimeZone |
timezone
The system timezone. |
private java.lang.String |
timeZoneDST
The time zone offset relative to GMT in text form when daylight saving is in operation. |
private java.lang.String |
timeZoneNoDST
The time zone offset relative to GMT in text form when daylight saving is not in operation. |
private java.io.PrintWriter |
writer
The PrintWriter to which we are currently logging, if any. |
private java.text.SimpleDateFormat |
yearFormatter
A date formatter to format a Date into a year string in the format "yyyy". |
| Fields inherited from class org.apache.catalina.valves.ValveBase |
container, containerLog, controller, domain, mserver, next, oname |
| Fields inherited from interface org.apache.catalina.Lifecycle |
AFTER_START_EVENT, AFTER_STOP_EVENT, BEFORE_START_EVENT, BEFORE_STOP_EVENT, DESTROY_EVENT, INIT_EVENT, PERIODIC_EVENT, START_EVENT, STOP_EVENT |
| Constructor Summary | |
AccessLogValve()
Construct a new instance of this class with default property values. |
|
| Method Summary | |
void |
addLifecycleListener(org.apache.catalina.LifecycleListener listener)
Add a lifecycle event listener to this component. |
private java.lang.String |
calculateTimeZoneOffset(long offset)
|
private void |
close()
Close the currently open log file (if any) |
org.apache.catalina.LifecycleListener[] |
findLifecycleListeners()
Get the lifecycle listeners associated with this lifecycle. |
java.lang.String |
getCondition()
Return whether the attribute name to look for when performing conditional loggging. |
private java.util.Date |
getDate()
This method returns a Date object that is accurate to within one second. |
java.lang.String |
getDirectory()
Return the directory in which we create log files. |
java.lang.String |
getFileDateFormat()
Return the date format date based log rotation. |
java.lang.String |
getInfo()
Return descriptive information about this implementation. |
java.lang.String |
getPattern()
Return the format pattern. |
java.lang.String |
getPrefix()
Return the log file prefix. |
java.lang.String |
getSuffix()
Return the log file suffix. |
private java.lang.String |
getTimeZone(java.util.Date date)
|
void |
invoke(org.apache.catalina.connector.Request request,
org.apache.catalina.connector.Response response)
Log a message summarizing the specified request and response, according to the format specified by the pattern property. |
boolean |
isResolveHosts()
Get the value of the resolve hosts flag. |
boolean |
isRotatable()
Should we rotate the logs |
void |
log(java.lang.String message,
java.util.Date date)
Log the specified message to the log file, switching files if the date has changed since the previous log call. |
private java.lang.String |
lookup(java.lang.String month)
Return the month abbreviation for the specified month, which must be a two-digit String. |
private void |
open()
Open the new log file for the date specified by dateStamp. |
void |
removeLifecycleListener(org.apache.catalina.LifecycleListener listener)
Remove a lifecycle event listener from this component. |
private java.lang.String |
replace(char pattern,
java.util.Date date,
org.apache.catalina.connector.Request request,
org.apache.catalina.connector.Response response,
long time)
Return the replacement text for the specified pattern character. |
private java.lang.String |
replace(java.lang.String header,
char type,
org.apache.catalina.connector.Request request,
org.apache.catalina.connector.Response response)
Return the replacement text for the specified "header/parameter". |
void |
setCondition(java.lang.String condition)
Set the ServletRequest.attribute to look for to perform conditional logging. |
void |
setDirectory(java.lang.String directory)
Set the directory in which we create log files. |
void |
setFileDateFormat(java.lang.String fileDateFormat)
Set the date format date based log rotation. |
void |
setPattern(java.lang.String pattern)
Set the format pattern, first translating any recognized alias. |
void |
setPrefix(java.lang.String prefix)
Set the log file prefix. |
void |
setResolveHosts(boolean resolveHosts)
Set the resolve hosts flag. |
void |
setRotatable(boolean rotatable)
Set the value is we should we rotate the logs |
void |
setSuffix(java.lang.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 |
backgroundProcess, createObjectName, getContainer, getContainerName, getController, getDomain, getNext, getObjectName, getParentName, postDeregister, postRegister, preDeregister, preRegister, setContainer, setController, setNext, setObjectName, toString |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
dateStamp
private java.lang.String dateStamp
- The as-of date for the currently open log file, or a zero-length
string if there is no open log file.
directory
private java.lang.String directory
- The directory in which log files are created.
info
protected static final java.lang.String info
- The descriptive information about this implementation.
- See Also:
- Constant Field Values
lifecycle
protected org.apache.catalina.util.LifecycleSupport lifecycle
- The lifecycle event support for this component.
months
protected static final java.lang.String[] months
- The set of month abbreviations for log messages.
common
private boolean common
- If the current log pattern is the same as the common access log
format pattern, then we'll set this variable to true and log in
a more optimal and hard-coded way.
combined
private boolean combined
- For the combined format (common, plus useragent and referer), we do
the same
pattern
private java.lang.String pattern
- The pattern used to format our access log lines.
prefix
private java.lang.String prefix
- The prefix that is added to log file filenames.
rotatable
private boolean rotatable
- Should we rotate our log file? Default is true (like old behavior)
sm
private org.apache.catalina.util.StringManager sm
- The string manager for this package.
started
private boolean started
- Has this component been started yet?
suffix
private java.lang.String suffix
- The suffix that is added to log file filenames.
writer
private java.io.PrintWriter writer
- The PrintWriter to which we are currently logging, if any.
dateFormatter
private java.text.SimpleDateFormat dateFormatter
- A date formatter to format a Date into a date in the format
"yyyy-MM-dd".
dayFormatter
private java.text.SimpleDateFormat dayFormatter
- A date formatter to format Dates into a day string in the format
"dd".
monthFormatter
private java.text.SimpleDateFormat monthFormatter
- A date formatter to format a Date into a month string in the format
"MM".
timeTakenFormatter
private java.text.DecimalFormat timeTakenFormatter
- Time taken formatter for 3 decimal places.
yearFormatter
private java.text.SimpleDateFormat yearFormatter
- A date formatter to format a Date into a year string in the format
"yyyy".
timeFormatter
private java.text.SimpleDateFormat timeFormatter
- A date formatter to format a Date into a time in the format
"kk:mm:ss" (kk is a 24-hour representation of the hour).
timezone
private java.util.TimeZone timezone
- The system timezone.
timeZoneNoDST
private java.lang.String timeZoneNoDST
- The time zone offset relative to GMT in text form when daylight saving
is not in operation.
timeZoneDST
private java.lang.String timeZoneDST
- The time zone offset relative to GMT in text form when daylight saving
is in operation.
currentDate
private java.util.Date currentDate
- The system time when we last updated the Date that this valve
uses for log lines.
space
private java.lang.String space
- When formatting log lines, we often use strings like this one (" ").
resolveHosts
private boolean resolveHosts
- Resolve hosts.
rotationLastChecked
private long rotationLastChecked
- Instant when the log daily rotation was last checked.
condition
private java.lang.String condition
- Are we doing conditional logging. default false.
fileDateFormat
private java.lang.String fileDateFormat
- Date format to place in log file name. Use at your own risk!
| Constructor Detail |
AccessLogValve
public AccessLogValve()
- Construct a new instance of this class with default property values.
| Method Detail |
getDirectory
public java.lang.String getDirectory()
- Return the directory in which we create log files.
setDirectory
public void setDirectory(java.lang.String directory)
- Set the directory in which we create log files.
getInfo
public java.lang.String getInfo()
- Return descriptive information about this implementation.
- Specified by:
getInfoin interfaceorg.apache.catalina.Valve- Overrides:
getInfoin classValveBase
getPattern
public java.lang.String getPattern()
- Return the format pattern.
setPattern
public void setPattern(java.lang.String pattern)
- Set the format pattern, first translating any recognized alias.
getPrefix
public java.lang.String getPrefix()
- Return the log file prefix.
setPrefix
public void setPrefix(java.lang.String prefix)
- Set the log file prefix.
isRotatable
public boolean isRotatable()
- Should we rotate the logs
setRotatable
public void setRotatable(boolean rotatable)
- Set the value is we should we rotate the logs
getSuffix
public java.lang.String getSuffix()
- Return the log file suffix.
setSuffix
public void setSuffix(java.lang.String suffix)
- Set the log file suffix.
setResolveHosts
public void setResolveHosts(boolean resolveHosts)
- Set the resolve hosts flag.
isResolveHosts
public boolean isResolveHosts()
- Get the value of the resolve hosts flag.
getCondition
public java.lang.String getCondition()
- Return whether the attribute name to look for when
performing conditional loggging. If null, every
request is logged.
setCondition
public void setCondition(java.lang.String condition)
- Set the ServletRequest.attribute to look for to perform
conditional logging. Set to null to log everything.
getFileDateFormat
public java.lang.String getFileDateFormat()
- Return the date format date based log rotation.
setFileDateFormat
public void setFileDateFormat(java.lang.String fileDateFormat)
- Set the date format date based log rotation.
invoke
public void invoke(org.apache.catalina.connector.Request request, org.apache.catalina.connector.Response response) throws java.io.IOException, javax.servlet.ServletException
- Log a message summarizing the specified request and response, according
to the format specified by the
patternproperty.- Specified by:
invokein interfaceorg.apache.catalina.Valve- Specified by:
invokein classValveBase
close
private void close()
- Close the currently open log file (if any)
log
public void log(java.lang.String message, java.util.Date date)
- Log the specified message to the log file, switching files if the date
has changed since the previous log call.
lookup
private java.lang.String lookup(java.lang.String month)
- Return the month abbreviation for the specified month, which must
be a two-digit String.
open
private void open()
- Open the new log file for the date specified by
dateStamp.
replace
private java.lang.String replace(char pattern, java.util.Date date, org.apache.catalina.connector.Request request, org.apache.catalina.connector.Response response, long time)
- Return the replacement text for the specified pattern character.
replace
private java.lang.String replace(java.lang.String header, char type, org.apache.catalina.connector.Request request, org.apache.catalina.connector.Response response)
- Return the replacement text for the specified "header/parameter".
getDate
private java.util.Date getDate()
- This method returns a Date object that is accurate to within one
second. If a thread calls this method to get a Date and it's been
less than 1 second since a new Date was created, this method
simply gives out the same Date again so that the system doesn't
spend time creating Date objects unnecessarily.
getTimeZone
private java.lang.String getTimeZone(java.util.Date date)
calculateTimeZoneOffset
private java.lang.String calculateTimeZoneOffset(long offset)
addLifecycleListener
public void addLifecycleListener(org.apache.catalina.LifecycleListener listener)
- Add a lifecycle event listener to this component.
- Specified by:
addLifecycleListenerin interfaceorg.apache.catalina.Lifecycle
findLifecycleListeners
public org.apache.catalina.LifecycleListener[] findLifecycleListeners()
- Get the lifecycle listeners associated with this lifecycle. If this
Lifecycle has no listeners registered, a zero-length array is returned.
- Specified by:
findLifecycleListenersin interfaceorg.apache.catalina.Lifecycle
removeLifecycleListener
public void removeLifecycleListener(org.apache.catalina.LifecycleListener listener)
- Remove a lifecycle event listener from this component.
- Specified by:
removeLifecycleListenerin interfaceorg.apache.catalina.Lifecycle
start
public void start()
throws org.apache.catalina.LifecycleException
- Prepare for the beginning of active use of the public methods of this
component. This method should be called after
configure(), and before any of the public methods of the component are utilized.- Specified by:
startin interfaceorg.apache.catalina.Lifecycle
stop
public void stop()
throws org.apache.catalina.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:
stopin interfaceorg.apache.catalina.Lifecycle
|
|||||||||
| Home >> All >> org >> apache >> catalina >> [ valves overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC