1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. See the NOTICE file distributed with
4 * this work for additional information regarding copyright ownership.
5 * The ASF licenses this file to You under the Apache License, Version 2.0
6 * (the "License"); you may not use this file except in compliance with
7 * the License. You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18 package org.apache.catalina;
19
20 import org.apache.catalina.connector.Request;
21 import org.apache.catalina.connector.Response;
22
23
24 /**
25 * Intended for use by a {@link Valve} to indicate that the {@link Valve}
26 * provides access logging. It is used by the Tomcat internals to identify a
27 * Valve that logs access requests so requests that are rejected
28 * earlier in the processing chain can still be added to the access log.
29 * Implementations of this interface should be robust against the provided
30 * {@link Request} and {@link Response} objects being null, having null
31 * attributes or any other 'oddness' that may result from attempting to log
32 * a request that was almost certainly rejected because it was mal-formed.
33 */
34 public interface AccessLog {
35
36 /**
37 * Name of request attribute used to override the remote address recorded by
38 * the AccessLog.
39 */
40 public static final String REMOTE_ADDR_ATTRIBUTE =
41 "org.apache.catalina.AccessLog.RemoteAddr";
42
43 /**
44 * Name of request attribute used to override remote host name recorded by
45 * the AccessLog.
46 */
47 public static final String REMOTE_HOST_ATTRIBUTE =
48 "org.apache.catalina.AccessLog.RemoteHost";
49
50 /**
51 * Name of request attribute used to override the protocol recorded by the
52 * AccessLog.
53 */
54 public static final String PROTOCOL_ATTRIBUTE =
55 "org.apache.catalina.AccessLog.Protocol";
56
57 /**
58 * Name of request attribute used to override the server name recorded by
59 * the AccessLog.
60 */
61 public static final String SERVER_NAME_ATTRIBUTE =
62 "org.apache.catalina.AccessLog.ServerName";
63
64 /**
65 * Name of request attribute used to override the server port recorded by
66 * the AccessLog.
67 */
68 public static final String SERVER_PORT_ATTRIBUTE =
69 "org.apache.catalina.AccessLog.ServerPort";
70
71
72 /**
73 * Add the request/response to the access log using the specified processing
74 * time.
75 *
76 * @param request Request (associated with the response) to log
77 * @param response Response (associated with the request) to log
78 * @param time Time taken to process the request/response in
79 * milliseconds (use 0 if not known)
80 */
81 public void log(Request request, Response response, long time);
82
83 /**
84 * Should this valve use request attributes for IP address, hostname,
85 * protocol and port used for the request?
86 *
87 * The attributes used are:
88 * <ul>
89 * <li>org.apache.catalina.RemoteAddr</li>
90 * <li>org.apache.catalina.RemoteHost</li>
91 * <li>org.apache.catalina.Protocol</li>
92 * <li>org.apache.catalina.ServerName</li>
93 * <li>org.apache.catalina.ServerPost</li>
94 * </ul>
95 *
96 * @param requestAttributesEnabled <code>true</code> causes the attributes
97 * to be used, <code>false</code> causes
98 * the original values to be used.
99 */
100 public void setRequestAttributesEnabled(boolean requestAttributesEnabled);
101
102 /**
103 * @see #setRequestAttributesEnabled(boolean)
104 * @return <code>true</code> if the attributes will be logged, otherwise
105 * <code>false</code>
106 */
107 public boolean getRequestAttributesEnabled();
108 }
109