时间:2021-07-01 10:21:17 帮助过:10人阅读
The default location for logs is a |
Access logging for undertow can be configured in a similar fashion
server.undertow.accesslog.enabled=true
server.undertow.accesslog.pattern=%t %a "%r" %s (%D ms)
Logs are stored in a logs
directory relative to the working directory of the application. This can be customized via server.undertow.accesslog.directory
.
http://docs.spring.io/spring-boot/docs/1.5.4.RELEASE/reference/htmlsingle/#howto-configure-accesslogs
Access logging is performed by valves that implement org.apache.catalina.AccessLog interface.
The Access Log Valve creates log files in the same format as those created by standard web servers. These logs can later be analyzed by standard log analysis tools to track page hit counts, user session activity, and so on. This Valve
uses self-contained logic to write its log files, which can be automatically rolled over at midnight each day. (The essential requirement for access logging is to handle a large continuous stream of data with low overhead. This Valve
does not use Apache Commons Logging, thus avoiding additional overhead and potentially complex configuration).
This Valve
may be associated with any Catalina container (Context
, Host
, or Engine
), and will record ALL requests processed by that container.
Some requests may be handled by Tomcat before they are passed to a container. These include redirects from /foo to /foo/ and the rejection of invalid requests. Where Tomcat can identify the Context
that would have handled the request, the request/response will be logged in the AccessLog
(s) associated Context
, Host
and Engine
. Where Tomcat cannot identify the Context
that would have handled the request, e.g. in cases where the URL is invalid, Tomcat will look first in the Engine
, then the default Host
for the Engine
and finally the ROOT (or default) Context
for the default Host
for an AccessLog
implementation. Tomcat will use the first AccessLog
implementation found to log those requests that are rejected before they are passed to a container.
The output file will be placed in the directory given by the directory
attribute. The name of the file is composed by concatenation of the configured prefix
, timestamp and suffix
. The format of the timestamp in the file name can be set using the fileDateFormat
attribute. This timestamp will be omitted if the file rotation is switched off by setting rotatable
to false
.
Warning: If multiple AccessLogValve instances are used, they should be configured to use different output files.
If sendfile is used, the response bytes will be written asynchronously in a separate thread and the access log valve will not know how many bytes were actually written. In this case, the number of bytes that was passed to the sendfile thread for writing will be recorded in the access log valve.
The Access Log Valve supports the following configuration attributes:
Attribute | Description |
---|---|
className |
Java class name of the implementation to use. This MUST be set to org.apache.catalina.valves.AccessLogValve to use the default access log valve. |
directory |
Absolute or relative pathname of a directory in which log files created by this valve will be placed. If a relative path is specified, it is interpreted as relative to $CATALINA_BASE. If no directory attribute is specified, the default value is "logs" (relative to $CATALINA_BASE). |
prefix |
The prefix added to the start of each log file‘s name. If not specified, the default value is "access_log". |
suffix |
The suffix added to the end of each log file‘s name. If not specified, the default value is "" (a zero-length string), meaning that no suffix will be added. |
fileDateFormat |
Allows a customized timestamp in the access log file name. The file is rotated whenever the formatted timestamp changes. The default value is |
rotatable |
Flag to determine if log rotation should occur. If set to |
renameOnRotate |
By default for a rotatable log the active access log file name will contain the current timestamp in |
pattern |
A formatting layout identifying the various information fields from the request and response to be logged, or the word |
encoding |
Character set used to write the log file. An empty string means to use the system default character set. Default value: use the system default character set. |
locale |
The locale used to format timestamps in the access log lines. Any timestamps configured using an explicit SimpleDateFormat pattern ( |
requestAttributesEnabled |
Set to |
conditionIf |
Turns on conditional logging. If set, requests will be logged only if |
conditionUnless |
Turns on conditional logging. If set, requests will be logged only if |
condition |
The same as |
buffered |
Flag to determine if logging will be buffered. If set to |
maxLogMessageBufferSize |
Log message buffers are usually recycled and re-used. To prevent excessive memory usage, if a buffer grows beyond this size it will be discarded. The default is |
resolveHosts |
This attribute is no longer supported. Use the connector attribute If you have |
Values for the pattern
attribute are made up of literal text strings, combined with pattern identifiers prefixed by the "%" character to cause replacement by the corresponding variable value from the current request and response. The following pattern codes are supported:
enableLookups
for the connector is false)%{xxx}p
below.There is also support to write information incoming or outgoing headers, cookies, session or request attributes and special timestamp formats. It is modeled after the Apache HTTP Server log configuration syntax. Each of them can be used multiple times with different xxx
keys:
%{xxx}i
write value of incoming header with name xxx
%{xxx}o
write value of outgoing header with name xxx
%{xxx}c
write value of cookie with name xxx
%{xxx}r
write value of ServletRequest attribute with name xxx
%{xxx}s
write value of HttpSession attribute with name xxx
%{xxx}p
write local (server) port (xxx==local
) or remote (client) port (xxx=remote
)%{xxx}t
write timestamp at the end of the request formatted using the enhanced SimpleDateFormat pattern xxx
All formats supported by SimpleDateFormat are allowed in %{xxx}t
. In addition the following extensions have been added:
sec
- number of seconds since the epochmsec
- number of milliseconds since the epochmsec_frac
- millisecond fractionThese formats can not be mixed with SimpleDateFormat formats in the same format token.
Furthermore one can define whether to log the timestamp for the request start time or the response finish time:
begin
or prefix begin:
chooses the request start timeend
or prefix end:
chooses the response finish timeBy adding multiple %{xxx}t
tokens to the pattern, one can also log both timestamps.
The shorthand pattern pattern="common"
corresponds to the Common Log Format defined by ‘%h %l %u %t "%r" %s %b‘.
The shorthand pattern pattern="combined"
appends the values of the Referer
and User-Agent
headers, each in double quotes, to the common
pattern.
When Tomcat is operating behind a reverse proxy, the client information logged by the Access Log Valve may represent the reverse proxy, the browser or some combination of the two depending on the configuration of Tomcat and the reverse proxy. For Tomcat configuration options see Proxies Support and the Proxy How-To. For reverse proxies that use mod_jk, see the generic proxy documentation. For other reverse proxies, consult their documentation.
The Extended Access Log Valve extends the Access Log Valve class, and so uses the same self-contained logging logic. This means it implements many of the same file handling attributes. The main difference to the standard AccessLogValve
is thatExtendedAccessLogValve
creates log files which conform to the Working Draft for the Extended Log File Format defined by the W3C.
The Extended Access Log Valve supports all configuration attributes of the standard Access Log Valve. Only the values used for className
and pattern
differ.
Attribute | Description |
---|---|
className |
Java class name of the implementation to use. This MUST be set to org.apache.catalina.valves.ExtendedAccessLogValve to use the extended access log valve. |
pattern |
A formatting layout identifying the various information fields from the request and response to be logged. See below for more information on configuring this attribute. |
Values for the pattern
attribute are made up of format tokens. Some of the tokens need an additional prefix. Possible prefixes are c
for "client", s
for "server", cs
for "client to server", sc
for "server to client" or x
for "application specific". Furthermore some tokens are completed by an additional selector. See the W3C specification for more information about the format.
The following format tokens are supported:
enableLookups
for the connector is false)For any of the x-H(XXX)
the following method will be called from the HttpServletRequest object:
x-H(authType)
: getAuthTypex-H(characterEncoding)
: getCharacterEncodingx-H(contentLength)
: getContentLengthx-H(locale)
: getLocalex-H(protocol)
: getProtocolx-H(remoteUser)
: getRemoteUserx-H(requestedSessionId)
: getRequestedSessionIdx-H(requestedSessionIdFromCookie)
: isRequestedSessionIdFromCookiex-H(requestedSessionIdValid)
: isRequestedSessionIdValidx-H(scheme)
: getSchemex-H(secure)
: isSecureThere is also support to write information about headers cookies, context, request or session attributes and request parameters.
cs(XXX)
for incoming request headers with name XXXsc(XXX)
for outgoing response headers with name XXXx-A(XXX)
for the servlet context attribute with name XXXx-C(XXX)
for the first cookie with name XXXx-O(XXX)
for a concatenation of all outgoing response headers with name XXXx-P(XXX)
for the URL encoded (using UTF-8) request parameter with name XXXx-R(XXX)
for the request attribute with name XXXx-S(XXX)
for the session attribute with name XXXhttps://tomcat.apache.org/tomcat-8.0-doc/config/valve.html#Access_Logging
Access Logging
标签:inf analysis location following get set custom wan create