tomcat access log pattern

来源:互联网 发布:淘宝号星级怎么算的 编辑:程序博客网 时间:2024/05/24 06:42


  • %a - Remote IP address
  • %A - Local IP address
  • %b - Bytes sent, excluding HTTP headers, or '-' if zero
  • %B - Bytes sent, excluding HTTP headers
  • %h - Remote host name (or IP address if resolveHosts is false)
  • %H - Request protocol
  • %l - Remote logical username from identd (always returns '-')
  • %m - Request method (GET, POST, etc.)
  • %p - Local port on which this request was received
  • %q - Query string (prepended with a '?' if it exists)
  • %r - First line of the request (method and request URI)
  • %s - HTTP status code of the response
  • %S - User session ID
  • %t - Date and time, in Common Log Format
  • %u - Remote user that was authenticated (if any), else '-'
  • %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
  • %I - Current request thread name (can compare later with stacktraces)

http://tomcat.apache.org/tomcat-6.0-doc/config/valve.html 


[Date and time] [Remote IP] [Bytes sent] [Request method] [HTTP status code of the response] [Time taken in millis] [User session ID] [Current request thread name] 
%t [%a] [%b] [%m] [%s] [%D] [%S] [%I] [%H://%v%U%q]

 <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log." suffix=".txt"
               pattern="%t [%a] [%b] [%m] [%s] [%D] [%S] [%I] [%H://%v%U%q]" />

proxy:

pattern:  %{X-Forwarded-For} 


 <Valve className="org.apache.catalina.valves.AccessLogValve" directory="logs"
               prefix="localhost_access_log." suffix=".txt"
               pattern="%{X-Forwarded-For} i %t [%a] [%b] [%m] [%s] [%D] [%S] [%I] [%H://%v%U%q]" />


http://www.docjar.org/docs/api/org/apache/catalina/valves/AccessLogValve.html


org.apache.catalina.valves
public class: AccessLogValve [javadoc | source

java.lang.Object   org.apache.catalina.valves.ValveBase      org.apache.catalina.valves.AccessLogValve

All Implemented Interfaces: 
    Lifecycle, Valve, MBeanRegistration, Contained

Direct Known Subclasses:
    FastCommonAccessLogValve, ExtendedAccessLogValve

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 Apachemod_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
  • %I - current Request thread name (can compare later with stacktraces)

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}i for incoming headers
  • %{xxx}o for outgoing response headers
  • %{xxx}c for a specific cookie
  • %{xxx}r xxx is an attribute in the ServletRequest
  • %{xxx}s xxx 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.

    author: Craig - R. McClanahan
    author: Jason - Brittain
    author: Remy - Maucherat
    author: Takayuki - Kaneko
    author: Peter - Rossbach
    version: $ - Revision: 832123 $ $Date: 2009-11-02 22:57:21 +0100 (Mon, 02 Nov 2009) $
Nested Class Summary:protected interface  AccessLogValve.AccessLogElement  AccessLogElement writes the partial message into the buffer. protected class  AccessLogValve.ThreadNameElement  write thread name - %I protected static class  AccessLogValve.LocalAddrElement  write local IP address - %A protected class  AccessLogValve.RemoteAddrElement  write remote IP address - %a protected class  AccessLogValve.HostElement  write remote host name - %h protected class  AccessLogValve.LogicalUserNameElement  write remote logical username from identd (always returns '-') - %l protected class  AccessLogValve.ProtocolElement  write request protocol - %H protected class  AccessLogValve.UserElement  write remote user that was authenticated (if any), else '-' - %u protected class  AccessLogValve.DateAndTimeElement  write date and time, in Common Log Format - %t protected class  AccessLogValve.RequestElement  write first line of the request (method and request URI) - %r protected class  AccessLogValve.HttpStatusCodeElement  write HTTP status code of the response - %s protected class  AccessLogValve.LocalPortElement  write local port on which this request was received - %p protected class  AccessLogValve.ByteSentElement  write bytes sent, excluding HTTP headers - %b, %B protected class  AccessLogValve.MethodElement  write request method (GET, POST, etc.) - %m protected class  AccessLogValve.ElapsedTimeElement  write time taken to process the request - %D, %T protected class  AccessLogValve.QueryElement  write Query string (prepended with a '?' if it exists) - %q protected class  AccessLogValve.SessionIdElement  write user session ID - %S protected class  AccessLogValve.RequestURIElement  write requested URL path - %U protected class  AccessLogValve.LocalServerNameElement  write local server name - %v protected class  AccessLogValve.StringElement  write any string protected class  AccessLogValve.HeaderElement  write incoming headers - %{xxx}i protected class  AccessLogValve.CookieElement  write a specific cookie - %{xxx}c protected class  AccessLogValve.ResponseHeaderElement  write a specific response header - %{xxx}o protected class  AccessLogValve.RequestAttributeElement  write an attribute in the ServletRequest - %{xxx}r protected class  AccessLogValve.SessionAttributeElement  write an attribute in the HttpSession - %{xxx}s Field Summaryprotected static final  Stringinfo   The descriptive information about this implementation. protected  LifecycleSupportlifecycle   The lifecycle event support for this component. protected static final  String[]months   The set of month abbreviations for log messages. protected  booleanenabled   enabled this component protected  Stringpattern   The pattern used to format our access log lines. protected  Stringprefix   The prefix that is added to log file filenames. protected  booleanrotatable   Should we rotate our log file? Default is true (like old behavior) protected  StringManagersm   The string manager for this package. protected  booleanstarted   Has this component been started yet? protected  Stringsuffix   The suffix that is added to log file filenames. protected  PrintWriterwriter   The PrintWriter to which we are currently logging, if any. protected  SimpleDateFormatfileDateFormatter   A date formatter to format a Date into a date in the format "yyyy-MM-dd". protected  FilecurrentLogFile   The current log file we are writing to. Helpful when checkExists is true. protected  Stringcondition   Are we doing conditional logging. default false. protected  StringfileDateFormat   Date format to place in log file name. Use at your own risk! protected  AccessLogElement[]logElements   Array of AccessLogElement, they will be used to make log message. Fields inherited from org.apache.catalina.valves.ValveBase:container,  containerLog,  info,  next,  sm,  domain,  oname,  mserver,  controllerMethod from org.apache.catalina.valves.AccessLogValve Summary:addLifecycleListener,   backgroundProcess,   createLogElements,   findLifecycleListeners,   getCondition,   getDirectory,   getEnabled,   getFileDateFormat,   getInfo,   getPattern,   getPrefix,   getSuffix,   invoke,  isBuffered,   isCheckExists,   isResolveHosts,   isRotatable,   log,   open,   removeLifecycleListener,   rotate,   setBuffered,   setCheckExists,   setCondition,   setDirectory,   setEnabled,   setFileDateFormat,   setPattern,   setPrefix,   setResolveHosts,   setRotatable,   setSuffix,   start,   stopMethods from org.apache.catalina.valves.ValveBase:backgroundProcess,   createObjectName,   event,   getContainer,   getContainerName,   getController,   getDomain,   getInfo,   getNext,   getObjectName,   getParentName,   invoke,   postDeregister,   postRegister,  preDeregister,   preRegister,   setContainer,   setController,   setNext,   setObjectName,   toStringMethods from java.lang.Object:clone,   equals,   finalize,   getClass,   hashCode,   notify,   notifyAll,   toString,   wait,   wait,   waitMethod from org.apache.catalina.valves.AccessLogValve Detail:
 public  void addLifecycleListener(LifecycleListener listener) 
    Add a lifecycle event listener to this component.
 public  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.
 protected AccessLogElement[] createLogElements() 
    parse pattern string and create the array of AccessLogElement
 public LifecycleListener[] findLifecycleListeners() 
    Get the lifecycle listeners associated with this lifecycle. If this Lifecycle has no listeners registered, a zero-length array is returned.
 public String getCondition() 
    Return whether the attribute name to look for when performing conditional loggging. If null, every request is logged.
 public String getDirectory() 
    Return the directory in which we create log files.
 public boolean getEnabled() 
 public String getFileDateFormat() 
    Return the date format date based log rotation.
 public String getInfo() 
    Return descriptive information about this implementation.
 public String getPattern() 
    Return the format pattern.
 public String getPrefix() 
    Return the log file prefix.
 public String getSuffix() 
    Return the log file suffix.
 public  void invoke(Request request,    Response response) throws IOException, ServletException 
    Log a message summarizing the specified request and response, according to the format specified by the pattern property.
 public boolean isBuffered() 
    Is the logging buffered
 public boolean isCheckExists() 
    Check for file existence before logging.
 public boolean isResolveHosts() 
    Get the value of the resolve hosts flag.
 public boolean isRotatable() 
    Should we rotate the logs
 public  void log(String message) 
    Log the specified message to the log file, switching files if the date has changed since the previous log call.
 protected synchronized  void open() 
    Open the new log file for the date specified by dateStamp.
 public  void removeLifecycleListener(LifecycleListener listener) 
    Remove a lifecycle event listener from this component.
 public synchronized 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.
 public  void setBuffered(boolean buffered) 
    Set the value if the logging should be buffered
 public  void setCheckExists(boolean checkExists) 
    Set whether to check for log file existence before logging.
 public  void setCondition(String condition) 
    Set the ServletRequest.attribute to look for to perform conditional logging. Set to null to log everything.
 public  void setDirectory(String directory) 
    Set the directory in which we create log files.
 public  void setEnabled(boolean enabled) 
 public  void setFileDateFormat(String fileDateFormat) 
    Set the date format date based log rotation.
 public  void setPattern(String pattern) 
    Set the format pattern, first translating any recognized alias.
 public  void setPrefix(String prefix) 
    Set the log file prefix.
 public  void setResolveHosts(boolean resolveHosts) 
    Set the resolve hosts flag.
 public  void setRotatable(boolean rotatable) 
    Set the value is we should we rotate the logs
 public  void setSuffix(String suffix) 
    Set the log file suffix.
 public  void start() throws 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.
 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.

0 0
原创粉丝点击