comparison src/org/eclipse/jetty/server/NCSARequestLog.java @ 855:fa6158f29c45

remove BufferDateCache and DateCache
author Franklin Schmidt <fschmidt@gmail.com>
date Tue, 20 Sep 2016 21:38:44 -0600
parents 359012f4e797
children
comparison
equal deleted inserted replaced
854:359012f4e797 855:fa6158f29c45
22 import java.io.OutputStream; 22 import java.io.OutputStream;
23 import java.io.OutputStreamWriter; 23 import java.io.OutputStreamWriter;
24 import java.io.Writer; 24 import java.io.Writer;
25 import java.io.File; 25 import java.io.File;
26 import java.io.FileOutputStream; 26 import java.io.FileOutputStream;
27 import java.text.DateFormat;
28 import java.text.SimpleDateFormat;
27 import java.util.Locale; 29 import java.util.Locale;
28 import java.util.TimeZone; 30 import java.util.TimeZone;
29 31
30 import javax.servlet.http.Cookie; 32 import javax.servlet.http.Cookie;
31 33
32 import org.eclipse.jetty.http.HttpHeaders; 34 import org.eclipse.jetty.http.HttpHeaders;
33 import org.eclipse.jetty.util.DateCache;
34 import org.eclipse.jetty.util.component.AbstractLifeCycle; 35 import org.eclipse.jetty.util.component.AbstractLifeCycle;
35 import org.slf4j.Logger; 36 import org.slf4j.Logger;
36 import org.slf4j.LoggerFactory; 37 import org.slf4j.LoggerFactory;
37 38
38 /** 39 /**
58 public long retainTime = 1000L*60*60*24*31; // 31 days 59 public long retainTime = 1000L*60*60*24*31; // 31 days
59 private boolean _closeOut; 60 private boolean _closeOut;
60 private boolean _preferProxiedForAddress; 61 private boolean _preferProxiedForAddress;
61 private String _logDateFormat = "dd/MMM/yyyy:HH:mm:ss Z"; 62 private String _logDateFormat = "dd/MMM/yyyy:HH:mm:ss Z";
62 private Locale _logLocale = Locale.getDefault(); 63 private Locale _logLocale = Locale.getDefault();
63 private String _logTimeZone = "GMT"; 64 public TimeZone timeZone = TimeZone.getTimeZone("GMT");
64 private boolean _logLatency = false; 65 private boolean _logLatency = false;
65 private boolean _logCookies = false; 66 private boolean _logCookies = false;
66 private boolean _logServer = false; 67 private boolean _logServer = false;
67 private boolean _logDispatch = false; 68 private boolean _logDispatch = false;
68 69
69 private transient OutputStream _out; 70 private transient OutputStream _out;
70 private transient DateCache _logDateCache; 71 private transient DateFormat dateFormat;
71 private transient Writer _writer; 72 private transient Writer _writer;
72 73
73 /* ------------------------------------------------------------ */ 74 /* ------------------------------------------------------------ */
74 /** 75 /**
75 * Create request log object with default settings. 76 * Create request log object with default settings.
169 return _logLocale; 170 return _logLocale;
170 } 171 }
171 172
172 /* ------------------------------------------------------------ */ 173 /* ------------------------------------------------------------ */
173 /** 174 /**
174 * Set the timezone of the request log.
175 *
176 * @param tz timezone string
177 */
178 public void setLogTimeZone(String tz)
179 {
180 _logTimeZone = tz;
181 }
182
183 /* ------------------------------------------------------------ */
184 /**
185 * Retrieve the timezone of the request log.
186 *
187 * @return timezone string
188 */
189 public String getLogTimeZone()
190 {
191 return _logTimeZone;
192 }
193
194 /* ------------------------------------------------------------ */
195 /**
196 * Set the extended request log format flag. 175 * Set the extended request log format flag.
197 * 176 *
198 * @param extended true - log the extended request information, 177 * @param extended true - log the extended request information,
199 * false - do not log the extended request information 178 * false - do not log the extended request information
200 */ 179 */
359 338
360 if (addr == null) 339 if (addr == null)
361 addr = request.getRemoteAddr(); 340 addr = request.getRemoteAddr();
362 341
363 buf.append(addr); 342 buf.append(addr);
364 buf.append(" - "); 343 buf.append(" - [");
365 344
366 buf.append(" ["); 345 synchronized(dateFormat) {
367 if (_logDateCache != null) 346 buf.append(dateFormat.format(request.getTimeStamp()));
368 buf.append(_logDateCache.format(request.getTimeStamp())); 347 }
369 else
370 buf.append(request.getTimeStampBuffer().toString());
371 348
372 buf.append("] \""); 349 buf.append("] \"");
373 buf.append(request.getMethod()); 350 buf.append(request.getMethod());
374 buf.append(' '); 351 buf.append(' ');
375 buf.append(request.getUri().toString()); 352 buf.append(request.getUri().toString());
518 * @see org.eclipse.jetty.util.component.AbstractLifeCycle#doStart() 495 * @see org.eclipse.jetty.util.component.AbstractLifeCycle#doStart()
519 */ 496 */
520 @Override 497 @Override
521 protected synchronized void doStart() throws Exception 498 protected synchronized void doStart() throws Exception
522 { 499 {
523 if (_logDateFormat != null) 500 dateFormat = new SimpleDateFormat(_logDateFormat,_logLocale);
524 { 501 dateFormat.setTimeZone(timeZone);
525 _logDateCache = new DateCache(_logDateFormat,_logLocale);
526 _logDateCache.setTimeZoneID(_logTimeZone);
527 }
528 502
529 if (_filename != null) { 503 if (_filename != null) {
530 File file = new File(_filename); 504 File file = new File(_filename);
531 if( file.exists() ) { 505 if( file.exists() ) {
532 File old = new File(_filename+".old"); 506 File old = new File(_filename+".old");
580 LOG.trace("",e); 554 LOG.trace("",e);
581 } 555 }
582 556
583 _out = null; 557 _out = null;
584 _closeOut = false; 558 _closeOut = false;
585 _logDateCache = null; 559 dateFormat = null;
586 _writer = null; 560 _writer = null;
587 } 561 }
588 } 562 }
589 } 563 }