Mercurial Hosting > luan
annotate src/org/eclipse/jetty/server/NCSARequestLog.java @ 821:292f2e31ab41
remove ErrorHandler.ErrorPageMapper
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 14 Sep 2016 00:48:03 -0600 |
parents | 8e9db0bbf4f9 |
children | 2afcb04f56a4 |
rev | line source |
---|---|
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
1 // |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
2 // ======================================================================== |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
3 // Copyright (c) 1995-2014 Mort Bay Consulting Pty. Ltd. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
4 // ------------------------------------------------------------------------ |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
5 // All rights reserved. This program and the accompanying materials |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
6 // are made available under the terms of the Eclipse Public License v1.0 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
7 // and Apache License v2.0 which accompanies this distribution. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
8 // |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
9 // The Eclipse Public License is available at |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
10 // http://www.eclipse.org/legal/epl-v10.html |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
11 // |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
12 // The Apache License v2.0 is available at |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
13 // http://www.opensource.org/licenses/apache2.0.php |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
14 // |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
15 // You may elect to redistribute this code under either of these licenses. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
16 // ======================================================================== |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
17 // |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
18 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
19 package org.eclipse.jetty.server; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
20 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
21 import java.io.IOException; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
22 import java.io.OutputStream; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
23 import java.io.OutputStreamWriter; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
24 import java.io.Writer; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
25 import java.util.Locale; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
26 import java.util.TimeZone; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
27 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
28 import javax.servlet.http.Cookie; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
29 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
30 import org.eclipse.jetty.http.HttpHeaders; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
31 import org.eclipse.jetty.http.PathMap; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
32 import org.eclipse.jetty.util.DateCache; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
33 import org.eclipse.jetty.util.RolloverFileOutputStream; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
34 import org.eclipse.jetty.util.StringUtil; |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
35 import org.eclipse.jetty.util.component.AbstractLifeCycle; |
820
8e9db0bbf4f9
remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
815
diff
changeset
|
36 import org.slf4j.Logger; |
8e9db0bbf4f9
remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
815
diff
changeset
|
37 import org.slf4j.LoggerFactory; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
38 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
39 /** |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
40 * This {@link RequestLog} implementation outputs logs in the pseudo-standard |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
41 * NCSA common log format. Configuration options allow a choice between the |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
42 * standard Common Log Format (as used in the 3 log format) and the Combined Log |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
43 * Format (single log format). This log format can be output by most web |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
44 * servers, and almost all web log analysis software can understand these |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
45 * formats. |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
46 * |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
47 * @org.apache.xbean.XBean element="ncsaLog" |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
48 */ |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
49 |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
50 /* ------------------------------------------------------------ */ |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
51 /** |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
52 */ |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
53 public class NCSARequestLog extends AbstractLifeCycle implements RequestLog |
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
54 { |
820
8e9db0bbf4f9
remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
815
diff
changeset
|
55 private static final Logger LOG = LoggerFactory.getLogger(NCSARequestLog.class); |
813 | 56 private static ThreadLocal<StringBuilder> _buffers = new ThreadLocal<StringBuilder>() |
57 { | |
58 @Override | |
59 protected StringBuilder initialValue() | |
60 { | |
61 return new StringBuilder(256); | |
62 } | |
63 }; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
64 |
813 | 65 private String _filename; |
66 private boolean _extended; | |
67 private boolean _append; | |
68 private int _retainDays; | |
69 private boolean _closeOut; | |
70 private boolean _preferProxiedForAddress; | |
71 private String _logDateFormat = "dd/MMM/yyyy:HH:mm:ss Z"; | |
72 private String _filenameDateFormat = null; | |
73 private Locale _logLocale = Locale.getDefault(); | |
74 private String _logTimeZone = "GMT"; | |
75 private String[] _ignorePaths; | |
76 private boolean _logLatency = false; | |
77 private boolean _logCookies = false; | |
78 private boolean _logServer = false; | |
79 private boolean _logDispatch = false; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
80 |
813 | 81 private transient OutputStream _out; |
82 private transient OutputStream _fileOut; | |
83 private transient DateCache _logDateCache; | |
84 private transient PathMap _ignorePathMap; | |
85 private transient Writer _writer; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
86 |
813 | 87 /* ------------------------------------------------------------ */ |
88 /** | |
89 * Create request log object with default settings. | |
90 */ | |
91 public NCSARequestLog() | |
92 { | |
93 _extended = true; | |
94 _append = true; | |
95 _retainDays = 31; | |
96 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
97 |
813 | 98 /* ------------------------------------------------------------ */ |
99 /** | |
100 * Create request log object with specified output file name. | |
101 * | |
102 * @param filename the file name for the request log. | |
103 * This may be in the format expected | |
104 * by {@link RolloverFileOutputStream} | |
105 */ | |
106 public NCSARequestLog(String filename) | |
107 { | |
108 _extended = true; | |
109 _append = true; | |
110 _retainDays = 31; | |
111 setFilename(filename); | |
112 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
113 |
813 | 114 /* ------------------------------------------------------------ */ |
115 /** | |
116 * Set the output file name of the request log. | |
117 * The file name may be in the format expected by | |
118 * {@link RolloverFileOutputStream}. | |
119 * | |
120 * @param filename file name of the request log | |
121 * | |
122 */ | |
123 public void setFilename(String filename) | |
124 { | |
125 if (filename != null) | |
126 { | |
127 filename = filename.trim(); | |
128 if (filename.length() == 0) | |
129 filename = null; | |
130 } | |
131 _filename = filename; | |
132 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
133 |
813 | 134 /* ------------------------------------------------------------ */ |
135 /** | |
136 * Retrieve the output file name of the request log. | |
137 * | |
138 * @return file name of the request log | |
139 */ | |
140 public String getFilename() | |
141 { | |
142 return _filename; | |
143 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
144 |
813 | 145 /* ------------------------------------------------------------ */ |
146 /** | |
147 * Retrieve the file name of the request log with the expanded | |
148 * date wildcard if the output is written to the disk using | |
149 * {@link RolloverFileOutputStream}. | |
150 * | |
151 * @return file name of the request log, or null if not applicable | |
152 */ | |
153 public String getDatedFilename() | |
154 { | |
155 if (_fileOut instanceof RolloverFileOutputStream) | |
156 return ((RolloverFileOutputStream)_fileOut).getDatedFilename(); | |
157 return null; | |
158 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
159 |
813 | 160 /* ------------------------------------------------------------ */ |
161 /** | |
162 * Set the timestamp format for request log entries in the file. | |
163 * If this is not set, the pre-formated request timestamp is used. | |
164 * | |
165 * @param format timestamp format string | |
166 */ | |
167 public void setLogDateFormat(String format) | |
168 { | |
169 _logDateFormat = format; | |
170 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
171 |
813 | 172 /* ------------------------------------------------------------ */ |
173 /** | |
174 * Retrieve the timestamp format string for request log entries. | |
175 * | |
176 * @return timestamp format string. | |
177 */ | |
178 public String getLogDateFormat() | |
179 { | |
180 return _logDateFormat; | |
181 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
182 |
813 | 183 /* ------------------------------------------------------------ */ |
184 /** | |
185 * Set the locale of the request log. | |
186 * | |
187 * @param logLocale locale object | |
188 */ | |
189 public void setLogLocale(Locale logLocale) | |
190 { | |
191 _logLocale = logLocale; | |
192 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
193 |
813 | 194 /* ------------------------------------------------------------ */ |
195 /** | |
196 * Retrieve the locale of the request log. | |
197 * | |
198 * @return locale object | |
199 */ | |
200 public Locale getLogLocale() | |
201 { | |
202 return _logLocale; | |
203 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
204 |
813 | 205 /* ------------------------------------------------------------ */ |
206 /** | |
207 * Set the timezone of the request log. | |
208 * | |
209 * @param tz timezone string | |
210 */ | |
211 public void setLogTimeZone(String tz) | |
212 { | |
213 _logTimeZone = tz; | |
214 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
215 |
813 | 216 /* ------------------------------------------------------------ */ |
217 /** | |
218 * Retrieve the timezone of the request log. | |
219 * | |
220 * @return timezone string | |
221 */ | |
222 public String getLogTimeZone() | |
223 { | |
224 return _logTimeZone; | |
225 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
226 |
813 | 227 /* ------------------------------------------------------------ */ |
228 /** | |
229 * Set the number of days before rotated log files are deleted. | |
230 * | |
231 * @param retainDays number of days to keep a log file | |
232 */ | |
233 public void setRetainDays(int retainDays) | |
234 { | |
235 _retainDays = retainDays; | |
236 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
237 |
813 | 238 /* ------------------------------------------------------------ */ |
239 /** | |
240 * Retrieve the number of days before rotated log files are deleted. | |
241 * | |
242 * @return number of days to keep a log file | |
243 */ | |
244 public int getRetainDays() | |
245 { | |
246 return _retainDays; | |
247 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
248 |
813 | 249 /* ------------------------------------------------------------ */ |
250 /** | |
251 * Set the extended request log format flag. | |
252 * | |
253 * @param extended true - log the extended request information, | |
254 * false - do not log the extended request information | |
255 */ | |
256 public void setExtended(boolean extended) | |
257 { | |
258 _extended = extended; | |
259 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
260 |
813 | 261 /* ------------------------------------------------------------ */ |
262 /** | |
263 * Retrieve the extended request log format flag. | |
264 * | |
265 * @return value of the flag | |
266 */ | |
267 public boolean isExtended() | |
268 { | |
269 return _extended; | |
270 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
271 |
813 | 272 /* ------------------------------------------------------------ */ |
273 /** | |
274 * Set append to log flag. | |
275 * | |
276 * @param append true - request log file will be appended after restart, | |
277 * false - request log file will be overwritten after restart | |
278 */ | |
279 public void setAppend(boolean append) | |
280 { | |
281 _append = append; | |
282 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
283 |
813 | 284 /* ------------------------------------------------------------ */ |
285 /** | |
286 * Retrieve append to log flag. | |
287 * | |
288 * @return value of the flag | |
289 */ | |
290 public boolean isAppend() | |
291 { | |
292 return _append; | |
293 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
294 |
813 | 295 /* ------------------------------------------------------------ */ |
296 /** | |
297 * Set request paths that will not be logged. | |
298 * | |
299 * @param ignorePaths array of request paths | |
300 */ | |
301 public void setIgnorePaths(String[] ignorePaths) | |
302 { | |
303 _ignorePaths = ignorePaths; | |
304 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
305 |
813 | 306 /* ------------------------------------------------------------ */ |
307 /** | |
308 * Retrieve the request paths that will not be logged. | |
309 * | |
310 * @return array of request paths | |
311 */ | |
312 public String[] getIgnorePaths() | |
313 { | |
314 return _ignorePaths; | |
315 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
316 |
813 | 317 /* ------------------------------------------------------------ */ |
318 /** | |
319 * Controls logging of the request cookies. | |
320 * | |
321 * @param logCookies true - values of request cookies will be logged, | |
322 * false - values of request cookies will not be logged | |
323 */ | |
324 public void setLogCookies(boolean logCookies) | |
325 { | |
326 _logCookies = logCookies; | |
327 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
328 |
813 | 329 /* ------------------------------------------------------------ */ |
330 /** | |
331 * Retrieve log cookies flag | |
332 * | |
333 * @return value of the flag | |
334 */ | |
335 public boolean getLogCookies() | |
336 { | |
337 return _logCookies; | |
338 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
339 |
813 | 340 /* ------------------------------------------------------------ */ |
341 /** | |
342 * Controls logging of the request hostname. | |
343 * | |
344 * @param logServer true - request hostname will be logged, | |
345 * false - request hostname will not be logged | |
346 */ | |
347 public void setLogServer(boolean logServer) | |
348 { | |
349 _logServer = logServer; | |
350 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
351 |
813 | 352 /* ------------------------------------------------------------ */ |
353 /** | |
354 * Retrieve log hostname flag. | |
355 * | |
356 * @return value of the flag | |
357 */ | |
358 public boolean getLogServer() | |
359 { | |
360 return _logServer; | |
361 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
362 |
813 | 363 /* ------------------------------------------------------------ */ |
364 /** | |
365 * Controls logging of request processing time. | |
366 * | |
367 * @param logLatency true - request processing time will be logged | |
368 * false - request processing time will not be logged | |
369 */ | |
370 public void setLogLatency(boolean logLatency) | |
371 { | |
372 _logLatency = logLatency; | |
373 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
374 |
813 | 375 /* ------------------------------------------------------------ */ |
376 /** | |
377 * Retrieve log request processing time flag. | |
378 * | |
379 * @return value of the flag | |
380 */ | |
381 public boolean getLogLatency() | |
382 { | |
383 return _logLatency; | |
384 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
385 |
813 | 386 /* ------------------------------------------------------------ */ |
387 /** | |
388 * Controls whether the actual IP address of the connection or | |
389 * the IP address from the X-Forwarded-For header will be logged. | |
390 * | |
391 * @param preferProxiedForAddress true - IP address from header will be logged, | |
392 * false - IP address from the connection will be logged | |
393 */ | |
394 public void setPreferProxiedForAddress(boolean preferProxiedForAddress) | |
395 { | |
396 _preferProxiedForAddress = preferProxiedForAddress; | |
397 } | |
398 | |
399 /* ------------------------------------------------------------ */ | |
400 /** | |
401 * Retrieved log X-Forwarded-For IP address flag. | |
402 * | |
403 * @return value of the flag | |
404 */ | |
405 public boolean getPreferProxiedForAddress() | |
406 { | |
407 return _preferProxiedForAddress; | |
408 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
409 |
813 | 410 /* ------------------------------------------------------------ */ |
411 /** | |
412 * Set the log file name date format. | |
413 * @see RolloverFileOutputStream#RolloverFileOutputStream(String, boolean, int, TimeZone, String, String) | |
414 * | |
415 * @param logFileDateFormat format string that is passed to {@link RolloverFileOutputStream} | |
416 */ | |
417 public void setFilenameDateFormat(String logFileDateFormat) | |
418 { | |
419 _filenameDateFormat = logFileDateFormat; | |
420 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
421 |
813 | 422 /* ------------------------------------------------------------ */ |
423 /** | |
424 * Retrieve the file name date format string. | |
425 * | |
426 * @return the log File Date Format | |
427 */ | |
428 public String getFilenameDateFormat() | |
429 { | |
430 return _filenameDateFormat; | |
431 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
432 |
813 | 433 /* ------------------------------------------------------------ */ |
434 /** | |
435 * Controls logging of the request dispatch time | |
436 * | |
437 * @param value true - request dispatch time will be logged | |
438 * false - request dispatch time will not be logged | |
439 */ | |
440 public void setLogDispatch(boolean value) | |
441 { | |
442 _logDispatch = value; | |
443 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
444 |
813 | 445 /* ------------------------------------------------------------ */ |
446 /** | |
447 * Retrieve request dispatch time logging flag | |
448 * | |
449 * @return value of the flag | |
450 */ | |
451 public boolean isLogDispatch() | |
452 { | |
453 return _logDispatch; | |
454 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
455 |
813 | 456 /* ------------------------------------------------------------ */ |
457 /** | |
458 * Writes the request and response information to the output stream. | |
459 * | |
460 * @see org.eclipse.jetty.server.RequestLog#log(org.eclipse.jetty.server.Request, org.eclipse.jetty.server.Response) | |
461 */ | |
462 public void log(Request request, Response response) | |
463 { | |
464 try | |
465 { | |
466 if (_ignorePathMap != null && _ignorePathMap.getMatch(request.getRequestURI()) != null) | |
467 return; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
468 |
813 | 469 if (_fileOut == null) |
470 return; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
471 |
813 | 472 StringBuilder buf= _buffers.get(); |
473 buf.setLength(0); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
474 |
813 | 475 if (_logServer) |
476 { | |
477 buf.append(request.getServerName()); | |
478 buf.append(' '); | |
479 } | |
480 | |
481 String addr = null; | |
482 if (_preferProxiedForAddress) | |
483 { | |
484 addr = request.getHeader(HttpHeaders.X_FORWARDED_FOR); | |
485 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
486 |
813 | 487 if (addr == null) |
488 addr = request.getRemoteAddr(); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
489 |
813 | 490 buf.append(addr); |
491 buf.append(" - "); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
492 |
813 | 493 buf.append(" ["); |
494 if (_logDateCache != null) | |
495 buf.append(_logDateCache.format(request.getTimeStamp())); | |
496 else | |
497 buf.append(request.getTimeStampBuffer().toString()); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
498 |
813 | 499 buf.append("] \""); |
500 buf.append(request.getMethod()); | |
501 buf.append(' '); | |
502 buf.append(request.getUri().toString()); | |
503 buf.append(' '); | |
504 buf.append(request.getProtocol()); | |
505 buf.append("\" "); | |
506 if (request.getAsyncContinuation().isInitial()) | |
507 { | |
508 int status = response.getStatus(); | |
509 if (status <= 0) | |
510 status = 404; | |
511 buf.append((char)('0' + ((status / 100) % 10))); | |
512 buf.append((char)('0' + ((status / 10) % 10))); | |
513 buf.append((char)('0' + (status % 10))); | |
514 } | |
515 else | |
516 buf.append("Async"); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
517 |
813 | 518 long responseLength = response.getContentCount(); |
519 if (responseLength >= 0) | |
520 { | |
521 buf.append(' '); | |
522 if (responseLength > 99999) | |
523 buf.append(responseLength); | |
524 else | |
525 { | |
526 if (responseLength > 9999) | |
527 buf.append((char)('0' + ((responseLength / 10000) % 10))); | |
528 if (responseLength > 999) | |
529 buf.append((char)('0' + ((responseLength / 1000) % 10))); | |
530 if (responseLength > 99) | |
531 buf.append((char)('0' + ((responseLength / 100) % 10))); | |
532 if (responseLength > 9) | |
533 buf.append((char)('0' + ((responseLength / 10) % 10))); | |
534 buf.append((char)('0' + (responseLength) % 10)); | |
535 } | |
536 buf.append(' '); | |
537 } | |
538 else | |
539 buf.append(" - "); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
540 |
813 | 541 |
542 if (_extended) | |
543 logExtended(request, response, buf); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
544 |
813 | 545 if (_logCookies) |
546 { | |
547 Cookie[] cookies = request.getCookies(); | |
548 if (cookies == null || cookies.length == 0) | |
549 buf.append(" -"); | |
550 else | |
551 { | |
552 buf.append(" \""); | |
553 for (int i = 0; i < cookies.length; i++) | |
554 { | |
555 if (i != 0) | |
556 buf.append(';'); | |
557 buf.append(cookies[i].getName()); | |
558 buf.append('='); | |
559 buf.append(cookies[i].getValue()); | |
560 } | |
561 buf.append('\"'); | |
562 } | |
563 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
564 |
813 | 565 if (_logDispatch || _logLatency) |
566 { | |
567 long now = System.currentTimeMillis(); | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
568 |
813 | 569 if (_logDispatch) |
570 { | |
571 long d = request.getDispatchTime(); | |
572 buf.append(' '); | |
573 buf.append(now - (d==0 ? request.getTimeStamp():d)); | |
574 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
575 |
813 | 576 if (_logLatency) |
577 { | |
578 buf.append(' '); | |
579 buf.append(now - request.getTimeStamp()); | |
580 } | |
581 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
582 |
813 | 583 buf.append(StringUtil.__LINE_SEPARATOR); |
584 | |
585 String log = buf.toString(); | |
586 write(log); | |
587 } | |
588 catch (IOException e) | |
589 { | |
820
8e9db0bbf4f9
remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
815
diff
changeset
|
590 LOG.warn("",e); |
813 | 591 } |
592 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
593 |
813 | 594 /* ------------------------------------------------------------ */ |
595 protected void write(String log) throws IOException | |
596 { | |
597 synchronized(this) | |
598 { | |
599 if (_writer==null) | |
600 return; | |
601 _writer.write(log); | |
602 _writer.flush(); | |
603 } | |
604 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
605 |
813 | 606 |
607 /* ------------------------------------------------------------ */ | |
608 /** | |
609 * Writes extended request and response information to the output stream. | |
610 * | |
611 * @param request request object | |
612 * @param response response object | |
613 * @param b StringBuilder to write to | |
614 * @throws IOException | |
615 */ | |
616 protected void logExtended(Request request, | |
617 Response response, | |
618 StringBuilder b) throws IOException | |
619 { | |
620 String referer = request.getHeader(HttpHeaders.REFERER); | |
621 if (referer == null) | |
622 b.append("\"-\" "); | |
623 else | |
624 { | |
625 b.append('"'); | |
626 b.append(referer); | |
627 b.append("\" "); | |
628 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
629 |
813 | 630 String agent = request.getHeader(HttpHeaders.USER_AGENT); |
631 if (agent == null) | |
632 b.append("\"-\" "); | |
633 else | |
634 { | |
635 b.append('"'); | |
636 b.append(agent); | |
637 b.append('"'); | |
638 } | |
639 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
640 |
813 | 641 /* ------------------------------------------------------------ */ |
642 /** | |
643 * Set up request logging and open log file. | |
644 * | |
645 * @see org.eclipse.jetty.util.component.AbstractLifeCycle#doStart() | |
646 */ | |
647 @Override | |
648 protected synchronized void doStart() throws Exception | |
649 { | |
650 if (_logDateFormat != null) | |
651 { | |
652 _logDateCache = new DateCache(_logDateFormat,_logLocale); | |
653 _logDateCache.setTimeZoneID(_logTimeZone); | |
654 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
655 |
813 | 656 if (_filename != null) |
657 { | |
658 _fileOut = new RolloverFileOutputStream(_filename,_append,_retainDays,TimeZone.getTimeZone(_logTimeZone),_filenameDateFormat,null); | |
659 _closeOut = true; | |
660 LOG.info("Opened " + getDatedFilename()); | |
661 } | |
662 else | |
663 _fileOut = System.err; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
664 |
813 | 665 _out = _fileOut; |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
666 |
813 | 667 if (_ignorePaths != null && _ignorePaths.length > 0) |
668 { | |
669 _ignorePathMap = new PathMap(); | |
670 for (int i = 0; i < _ignorePaths.length; i++) | |
671 _ignorePathMap.put(_ignorePaths[i],_ignorePaths[i]); | |
672 } | |
673 else | |
674 _ignorePathMap = null; | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
675 |
813 | 676 synchronized(this) |
677 { | |
678 _writer = new OutputStreamWriter(_out); | |
679 } | |
680 super.doStart(); | |
681 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
682 |
813 | 683 /* ------------------------------------------------------------ */ |
684 /** | |
685 * Close the log file and perform cleanup. | |
686 * | |
687 * @see org.eclipse.jetty.util.component.AbstractLifeCycle#doStop() | |
688 */ | |
689 @Override | |
690 protected void doStop() throws Exception | |
691 { | |
692 synchronized (this) | |
693 { | |
694 super.doStop(); | |
695 try | |
696 { | |
697 if (_writer != null) | |
698 _writer.flush(); | |
699 } | |
700 catch (IOException e) | |
701 { | |
820
8e9db0bbf4f9
remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
815
diff
changeset
|
702 LOG.trace("",e); |
813 | 703 } |
704 if (_out != null && _closeOut) | |
705 try | |
706 { | |
707 _out.close(); | |
708 } | |
709 catch (IOException e) | |
710 { | |
820
8e9db0bbf4f9
remove org.eclipse.jetty.util.log and upgrade slf4j
Franklin Schmidt <fschmidt@gmail.com>
parents:
815
diff
changeset
|
711 LOG.trace("",e); |
813 | 712 } |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
713 |
813 | 714 _out = null; |
715 _fileOut = null; | |
716 _closeOut = false; | |
717 _logDateCache = null; | |
718 _writer = null; | |
719 } | |
720 } | |
802
3428c60d7cfc
replace jetty jars with source
Franklin Schmidt <fschmidt@gmail.com>
parents:
diff
changeset
|
721 } |