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