Package org.apache.catalina.valves
Class AccessLogValve
java.lang.Object
org.apache.catalina.util.LifecycleBase
org.apache.catalina.util.LifecycleMBeanBase
org.apache.catalina.valves.ValveBase
org.apache.catalina.valves.AbstractAccessLogValve
org.apache.catalina.valves.AccessLogValve
- All Implemented Interfaces:
- MBeanRegistration,- AccessLog,- Contained,- JmxEnabled,- Lifecycle,- Valve
- Direct Known Subclasses:
- ExtendedAccessLogValve,- JsonAccessLogValve
This is a concrete implementation of 
AbstractAccessLogValve that outputs the access log to a file. The
 features of this implementation include:
 - Automatic date-based rollover of log files
- Optional log file rotation
 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.
 
- 
Nested Class SummaryNested classes/interfaces inherited from class org.apache.catalina.valves.AbstractAccessLogValveAbstractAccessLogValve.AccessLogElement, AbstractAccessLogValve.ByteSentElement, AbstractAccessLogValve.CachedElement, AbstractAccessLogValve.ConnectionStatusElement, 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.UserElementNested classes/interfaces inherited from interface org.apache.catalina.LifecycleLifecycle.SingleUse
- 
Field SummaryFieldsModifier and TypeFieldDescriptionprotected FileThe current log file we are writing to.protected StringCharacter set used by the log file.protected StringDate format to place in log file name.protected SimpleDateFormatA date formatter to format a Date using the format given byfileDateFormat.protected StringThe prefix that is added to log file filenames.protected booleanShould we defer inclusion of the date stamp in the file name until rotate time?protected booleanShould we rotate our log file?protected StringThe suffix that is added to log file filenames.protected PrintWriterThe PrintWriter to which we are currently logging, if any.Fields inherited from class org.apache.catalina.valves.AbstractAccessLogValvecachedElements, condition, conditionIf, enabled, locale, localeName, logElements, pattern, requestAttributesEnabledFields inherited from class org.apache.catalina.valves.ValveBaseasyncSupported, container, containerLog, next, smFields inherited from interface org.apache.catalina.AccessLogPROTOCOL_ATTRIBUTE, REMOTE_ADDR_ATTRIBUTE, REMOTE_HOST_ATTRIBUTE, SERVER_NAME_ATTRIBUTE, SERVER_PORT_ATTRIBUTEFields inherited from interface org.apache.catalina.LifecycleAFTER_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 SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidExecute a periodic task, such as reloading, etc.Return the character set name that is used to write the log file.intbooleanIs the logging buffered.booleanCheck for file existence before logging.booleanShould we defer inclusion of the date stamp in the file name until rotate time.booleanShould we rotate the access log.voidlog(CharArrayWriter message) Log the specified message to the log file, switching files if the date has changed since the previous log call.protected voidopen()Open the new log file for the date specified bydateStamp.voidrotate()Rotate the log file if necessary.booleanRename the existing log file to something else.voidsetBuffered(boolean buffered) Set the value if the logging should be bufferedvoidsetCheckExists(boolean checkExists) Set whether to check for log file existence before logging.voidsetDirectory(String directory) Set the directory in which we create log files.voidsetEncoding(String encoding) Set the character set that is used to write the log file.voidsetFileDateFormat(String fileDateFormat) Set the date format date based log rotation.voidsetMaxDays(int maxDays) voidSet the log file prefix.voidsetRenameOnRotate(boolean renameOnRotate) Set the value if we should defer inclusion of the date stamp in the file name until rotate timevoidsetRotatable(boolean rotatable) Configure whether the access log should be rotated.voidSet the log file suffix.protected voidStart this component and implement the requirements ofLifecycleBase.startInternal().protected voidStop this component and implement the requirements ofLifecycleBase.stopInternal().Methods inherited from class org.apache.catalina.valves.AbstractAccessLogValvecreateAccessLogElement, createAccessLogElement, createLogElements, escapeAndAppend, findLocale, getCondition, getConditionIf, getConditionUnless, getEnabled, getIpv6Canonical, getLocale, getMaxLogMessageBufferSize, getPattern, getRequestAttributesEnabled, invoke, log, setCondition, setConditionIf, setConditionUnless, setEnabled, setIpv6Canonical, setLocale, setMaxLogMessageBufferSize, setPattern, setRequestAttributesEnabledMethods inherited from class org.apache.catalina.valves.ValveBasegetContainer, getDomainInternal, getNext, getObjectNameKeyProperties, initInternal, isAsyncSupported, setAsyncSupported, setContainer, setNext, toStringMethods inherited from class org.apache.catalina.util.LifecycleMBeanBasedestroyInternal, getDomain, getObjectName, postDeregister, postRegister, preDeregister, preRegister, register, setDomain, unregister, unregisterMethods inherited from class org.apache.catalina.util.LifecycleBaseaddLifecycleListener, destroy, findLifecycleListeners, fireLifecycleEvent, getState, getStateName, getThrowOnFailure, init, removeLifecycleListener, setState, setState, setThrowOnFailure, start, stop
- 
Field Details- 
prefixThe prefix that is added to log file filenames.
- 
rotatableprotected boolean rotatableShould we rotate our log file? Default is true (like old behavior)
- 
renameOnRotateprotected boolean renameOnRotateShould we defer inclusion of the date stamp in the file name until rotate time? Default is false.
- 
suffixThe suffix that is added to log file filenames.
- 
writerThe PrintWriter to which we are currently logging, if any.
- 
fileDateFormatterA date formatter to format a Date using the format given byfileDateFormat.
- 
currentLogFileThe current log file we are writing to. Helpful when checkExists is true.
- 
fileDateFormatDate format to place in log file name.
- 
encodingCharacter set used by the log file. If it isnull, UTF-8 will be used. An empty string will be treated asnullwhen this property is assigned.
 
- 
- 
Constructor Details- 
AccessLogValvepublic AccessLogValve()
 
- 
- 
Method Details- 
getMaxDayspublic int getMaxDays()
- 
setMaxDayspublic void setMaxDays(int maxDays) 
- 
getDirectory- Returns:
- the directory in which we create log files.
 
- 
setDirectorySet the directory in which we create log files.- Parameters:
- directory- The new log file directory
 
- 
isCheckExistspublic boolean isCheckExists()Check for file existence before logging.- Returns:
- trueif file existence is checked first
 
- 
setCheckExistspublic void setCheckExists(boolean checkExists) Set whether to check for log file existence before logging.- Parameters:
- checkExists- true meaning to check for file existence.
 
- 
getPrefix- Returns:
- the log file prefix.
 
- 
setPrefixSet the log file prefix.- Parameters:
- prefix- The new log file prefix
 
- 
isRotatablepublic boolean isRotatable()Should we rotate the access log.- Returns:
- trueif the access log should be rotated
 
- 
setRotatablepublic void setRotatable(boolean rotatable) Configure whether the access log should be rotated.- Parameters:
- rotatable- true if the log should be rotated
 
- 
isRenameOnRotatepublic boolean isRenameOnRotate()Should we defer inclusion of the date stamp in the file name until rotate time.- Returns:
- trueif the logs file names are time stamped only when they are rotated
 
- 
setRenameOnRotatepublic void setRenameOnRotate(boolean renameOnRotate) Set the value if we should defer inclusion of the date stamp in the file name until rotate time- Parameters:
- renameOnRotate- true if defer inclusion of date stamp
 
- 
isBufferedpublic boolean isBuffered()Is the logging buffered. Usually buffering can increase performance.- Returns:
- trueif the logging uses a buffer
 
- 
setBufferedpublic void setBuffered(boolean buffered) Set the value if the logging should be buffered- Parameters:
- buffered-- trueif buffered.
 
- 
getSuffix- Returns:
- the log file suffix.
 
- 
setSuffixSet the log file suffix.- Parameters:
- suffix- The new log file suffix
 
- 
getFileDateFormat- Returns:
- the date format date based log rotation.
 
- 
setFileDateFormatSet the date format date based log rotation.- Parameters:
- fileDateFormat- The format for the file timestamp
 
- 
getEncodingReturn the character set name that is used to write the log file.- Returns:
- Character set name, or nullif the default character set is used.
 
- 
setEncodingSet the character set that is used to write the log file.- Parameters:
- encoding- The name of the character set.
 
- 
backgroundProcesspublic void backgroundProcess()Execute a periodic task, such as reloading, etc. This method will be invoked inside the classloading context of this container. Unexpected throwables will be caught and logged.- Specified by:
- backgroundProcessin interface- Valve
- Overrides:
- backgroundProcessin class- ValveBase
 
- 
rotatepublic void rotate()Rotate the log file if necessary.
- 
rotateRename 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
 
- 
logLog the specified message to the log file, switching files if the date has changed since the previous log call.- Specified by:
- login class- AbstractAccessLogValve
- Parameters:
- message- Message to be logged
 
- 
openprotected void open()Open the new log file for the date specified bydateStamp.
- 
startInternalStart this component and implement the requirements ofLifecycleBase.startInternal().- Overrides:
- startInternalin class- ValveBase
- Throws:
- LifecycleException- if this component detects a fatal error that prevents this component from being used
 
- 
stopInternalStop this component and implement the requirements ofLifecycleBase.stopInternal().- Overrides:
- stopInternalin class- ValveBase
- Throws:
- LifecycleException- if this component detects a fatal error that prevents this component from being used
 
 
-