public class AccessLogValve extends AbstractAccessLogValve
AbstractAccessLogValve
that
outputs the access log to a file. The features of this implementation
include:
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 and start writing a new log file.
AbstractAccessLogValve.AccessLogElement, AbstractAccessLogValve.ByteSentElement, AbstractAccessLogValve.CookieElement, AbstractAccessLogValve.DateAndTimeElement, AbstractAccessLogValve.DateFormatCache, AbstractAccessLogValve.ElapsedTimeElement, AbstractAccessLogValve.FirstByteTimeElement, AbstractAccessLogValve.HeaderElement, AbstractAccessLogValve.HostElement, AbstractAccessLogValve.HttpStatusCodeElement, AbstractAccessLogValve.LocalAddrElement, AbstractAccessLogValve.LocalServerNameElement, AbstractAccessLogValve.LogicalUserNameElement, AbstractAccessLogValve.MethodElement, AbstractAccessLogValve.PortElement, AbstractAccessLogValve.ProtocolElement, AbstractAccessLogValve.QueryElement, AbstractAccessLogValve.RemoteAddrElement, AbstractAccessLogValve.RequestAttributeElement, AbstractAccessLogValve.RequestElement, AbstractAccessLogValve.RequestURIElement, AbstractAccessLogValve.ResponseHeaderElement, AbstractAccessLogValve.SessionAttributeElement, AbstractAccessLogValve.SessionIdElement, AbstractAccessLogValve.StringElement, AbstractAccessLogValve.ThreadNameElement, AbstractAccessLogValve.UserElement
Lifecycle.SingleUse
Modifier and Type | Field and Description |
---|---|
protected java.io.File |
currentLogFile
The current log file we are writing to.
|
protected java.lang.String |
encoding
Character set used by the log file.
|
protected java.lang.String |
fileDateFormat
Date format to place in log file name.
|
protected java.text.SimpleDateFormat |
fileDateFormatter
A date formatter to format a Date using the format
given by
fileDateFormat . |
protected java.lang.String |
prefix
The prefix that is added to log file filenames.
|
protected boolean |
renameOnRotate
Should we defer inclusion of the date stamp in the file
name until rotate time?
|
protected boolean |
rotatable
Should we rotate our log file?
|
protected java.lang.String |
suffix
The suffix that is added to log file filenames.
|
protected java.io.PrintWriter |
writer
The PrintWriter to which we are currently logging, if any.
|
condition, conditionIf, enabled, locale, localeName, logElements, pattern, requestAttributesEnabled
asyncSupported, container, containerLog, next, sm
mserver
PROTOCOL_ATTRIBUTE, REMOTE_ADDR_ATTRIBUTE, REMOTE_HOST_ATTRIBUTE, SERVER_PORT_ATTRIBUTE
AFTER_DESTROY_EVENT, AFTER_INIT_EVENT, AFTER_START_EVENT, AFTER_STOP_EVENT, BEFORE_DESTROY_EVENT, BEFORE_INIT_EVENT, BEFORE_START_EVENT, BEFORE_STOP_EVENT, CONFIGURE_START_EVENT, CONFIGURE_STOP_EVENT, PERIODIC_EVENT, START_EVENT, STOP_EVENT
Constructor and Description |
---|
AccessLogValve() |
Modifier and Type | Method and Description |
---|---|
void |
backgroundProcess()
Execute a periodic task, such as reloading, etc.
|
java.lang.String |
getDirectory()
Return the directory in which we create log files.
|
java.lang.String |
getEncoding()
Return the character set name that is used to write the log file.
|
java.lang.String |
getFileDateFormat()
Return the date format date based log rotation.
|
java.lang.String |
getPrefix()
Return the log file prefix.
|
java.lang.String |
getSuffix()
Return the log file suffix.
|
boolean |
isBuffered()
Is the logging buffered
|
boolean |
isCheckExists()
Check for file existence before logging.
|
boolean |
isRenameOnRotate()
Should we defer inclusion of the date stamp in the file
name until rotate time
|
boolean |
isRotatable()
Should we rotate the access log.
|
void |
log(java.io.CharArrayWriter message)
Log the specified message to the log file, switching files if the date
has changed since the previous log call.
|
protected void |
open()
Open the new log file for the date specified by
dateStamp . |
void |
rotate()
Rotate the log file if necessary.
|
boolean |
rotate(java.lang.String newFileName)
Rename the existing log file to something else.
|
void |
setBuffered(boolean buffered)
Set the value if the logging should be buffered
|
void |
setCheckExists(boolean checkExists)
Set whether to check for log file existence before logging.
|
void |
setDirectory(java.lang.String directory)
Set the directory in which we create log files.
|
void |
setEncoding(java.lang.String encoding)
Set the character set that is used to write the log file.
|
void |
setFileDateFormat(java.lang.String fileDateFormat)
Set the date format date based log rotation.
|
void |
setPrefix(java.lang.String prefix)
Set the log file prefix.
|
void |
setRenameOnRotate(boolean renameOnRotate)
Set the value if we should defer inclusion of the date
stamp in the file name until rotate time
|
void |
setRotatable(boolean rotatable)
Configure whether the access log should be rotated.
|
void |
setSuffix(java.lang.String suffix)
Set the log file suffix.
|
protected void |
startInternal()
Start this component and implement the requirements
of
LifecycleBase.startInternal() . |
protected void |
stopInternal()
Stop this component and implement the requirements
of
LifecycleBase.stopInternal() . |
createAccessLogElement, createAccessLogElement, createLogElements, findLocale, getCondition, getConditionIf, getConditionUnless, getEnabled, getLocale, getPattern, getRequestAttributesEnabled, invoke, log, setCondition, setConditionIf, setConditionUnless, setEnabled, setLocale, setPattern, setRequestAttributesEnabled
event, getContainer, getDomainInternal, getNext, getObjectNameKeyProperties, initInternal, isAsyncSupported, setAsyncSupported, setContainer, setNext, toString
destroyInternal, getDomain, getObjectName, postDeregister, postRegister, preDeregister, preRegister, register, setDomain, unregister
addLifecycleListener, destroy, findLifecycleListeners, fireLifecycleEvent, getState, getStateName, init, removeLifecycleListener, setState, setState, start, stop
protected java.lang.String prefix
protected boolean rotatable
protected boolean renameOnRotate
protected java.lang.String suffix
protected java.io.PrintWriter writer
protected java.text.SimpleDateFormat fileDateFormatter
fileDateFormat
.protected java.io.File currentLogFile
protected java.lang.String fileDateFormat
protected java.lang.String encoding
null
, the
system default character set will be used. An empty string will be
treated as null
when this property is assigned.public java.lang.String getDirectory()
public void setDirectory(java.lang.String directory)
directory
- The new log file directorypublic boolean isCheckExists()
public void setCheckExists(boolean checkExists)
checkExists
- true meaning to check for file existence.public java.lang.String getPrefix()
public void setPrefix(java.lang.String prefix)
prefix
- The new log file prefixpublic boolean isRotatable()
true
if the access log should be rotatedpublic void setRotatable(boolean rotatable)
rotatable
- true if the log should be rotatedpublic boolean isRenameOnRotate()
public void setRenameOnRotate(boolean renameOnRotate)
renameOnRotate
- true if defer inclusion of date stamppublic boolean isBuffered()
public void setBuffered(boolean buffered)
buffered
- true if buffered.public java.lang.String getSuffix()
public void setSuffix(java.lang.String suffix)
suffix
- The new log file suffixpublic java.lang.String getFileDateFormat()
public void setFileDateFormat(java.lang.String fileDateFormat)
public java.lang.String getEncoding()
null
if the system default
character set is used.public void setEncoding(java.lang.String encoding)
encoding
- The name of the character set.public void backgroundProcess()
backgroundProcess
in interface Valve
backgroundProcess
in class ValveBase
public void rotate()
public boolean rotate(java.lang.String newFileName)
newFileName
- The file name to move the log file entry topublic void log(java.io.CharArrayWriter message)
log
in class AbstractAccessLogValve
message
- Message to be loggedprotected void open()
dateStamp
.protected void startInternal() throws LifecycleException
LifecycleBase.startInternal()
.startInternal
in class AbstractAccessLogValve
LifecycleException
- if this component detects a fatal error
that prevents this component from being usedprotected void stopInternal() throws LifecycleException
LifecycleBase.stopInternal()
.stopInternal
in class AbstractAccessLogValve
LifecycleException
- if this component detects a fatal error
that prevents this component from being usedCopyright © 2000-2018 Apache Software Foundation. All Rights Reserved.