Mercurial Hosting > luan
diff src/org/eclipse/jetty/server/NCSARequestLog.java @ 853:3242aff51053
remove RolloverFileOutputStream and cleanup NCSARequestLog
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Tue, 20 Sep 2016 00:23:56 -0600 |
parents | 175577dab6d8 |
children | 359012f4e797 |
line wrap: on
line diff
--- a/src/org/eclipse/jetty/server/NCSARequestLog.java Mon Sep 19 20:08:16 2016 -0600 +++ b/src/org/eclipse/jetty/server/NCSARequestLog.java Tue Sep 20 00:23:56 2016 -0600 @@ -22,6 +22,8 @@ import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.Writer; +import java.io.File; +import java.io.FileOutputStream; import java.util.Locale; import java.util.TimeZone; @@ -29,8 +31,6 @@ import org.eclipse.jetty.http.HttpHeaders; import org.eclipse.jetty.util.DateCache; -import org.eclipse.jetty.util.RolloverFileOutputStream; -import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.component.AbstractLifeCycle; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -52,23 +52,15 @@ public class NCSARequestLog extends AbstractLifeCycle implements RequestLog { private static final Logger LOG = LoggerFactory.getLogger(NCSARequestLog.class); - private static ThreadLocal<StringBuilder> _buffers = new ThreadLocal<StringBuilder>() - { - @Override - protected StringBuilder initialValue() - { - return new StringBuilder(256); - } - }; + private static final String __LINE_SEPARATOR= + System.getProperty("line.separator","\n"); private String _filename; private boolean _extended; - private boolean _append; - private int _retainDays; + public long sizeLimit = 1048576L; private boolean _closeOut; private boolean _preferProxiedForAddress; private String _logDateFormat = "dd/MMM/yyyy:HH:mm:ss Z"; - private String _filenameDateFormat = null; private Locale _logLocale = Locale.getDefault(); private String _logTimeZone = "GMT"; private boolean _logLatency = false; @@ -77,7 +69,6 @@ private boolean _logDispatch = false; private transient OutputStream _out; - private transient OutputStream _fileOut; private transient DateCache _logDateCache; private transient Writer _writer; @@ -88,8 +79,6 @@ public NCSARequestLog() { _extended = true; - _append = true; - _retainDays = 31; } /* ------------------------------------------------------------ */ @@ -103,8 +92,6 @@ public NCSARequestLog(String filename) { _extended = true; - _append = true; - _retainDays = 31; setFilename(filename); } @@ -141,21 +128,6 @@ /* ------------------------------------------------------------ */ /** - * Retrieve the file name of the request log with the expanded - * date wildcard if the output is written to the disk using - * {@link RolloverFileOutputStream}. - * - * @return file name of the request log, or null if not applicable - */ - public String getDatedFilename() - { - if (_fileOut instanceof RolloverFileOutputStream) - return ((RolloverFileOutputStream)_fileOut).getDatedFilename(); - return null; - } - - /* ------------------------------------------------------------ */ - /** * Set the timestamp format for request log entries in the file. * If this is not set, the pre-formated request timestamp is used. * @@ -223,28 +195,6 @@ /* ------------------------------------------------------------ */ /** - * Set the number of days before rotated log files are deleted. - * - * @param retainDays number of days to keep a log file - */ - public void setRetainDays(int retainDays) - { - _retainDays = retainDays; - } - - /* ------------------------------------------------------------ */ - /** - * Retrieve the number of days before rotated log files are deleted. - * - * @return number of days to keep a log file - */ - public int getRetainDays() - { - return _retainDays; - } - - /* ------------------------------------------------------------ */ - /** * Set the extended request log format flag. * * @param extended true - log the extended request information, @@ -268,29 +218,6 @@ /* ------------------------------------------------------------ */ /** - * Set append to log flag. - * - * @param append true - request log file will be appended after restart, - * false - request log file will be overwritten after restart - */ - public void setAppend(boolean append) - { - _append = append; - } - - /* ------------------------------------------------------------ */ - /** - * Retrieve append to log flag. - * - * @return value of the flag - */ - public boolean isAppend() - { - return _append; - } - - /* ------------------------------------------------------------ */ - /** * Controls logging of the request cookies. * * @param logCookies true - values of request cookies will be logged, @@ -383,29 +310,6 @@ } /* ------------------------------------------------------------ */ - /** - * Set the log file name date format. - * @see RolloverFileOutputStream#RolloverFileOutputStream(String, boolean, int, TimeZone, String, String) - * - * @param logFileDateFormat format string that is passed to {@link RolloverFileOutputStream} - */ - public void setFilenameDateFormat(String logFileDateFormat) - { - _filenameDateFormat = logFileDateFormat; - } - - /* ------------------------------------------------------------ */ - /** - * Retrieve the file name date format string. - * - * @return the log File Date Format - */ - public String getFilenameDateFormat() - { - return _filenameDateFormat; - } - - /* ------------------------------------------------------------ */ /** * Controls logging of the request dispatch time * @@ -438,11 +342,10 @@ { try { - if (_fileOut == null) + if (_out == null) return; - StringBuilder buf= _buffers.get(); - buf.setLength(0); + StringBuilder buf = new StringBuilder(256); if (_logServer) { @@ -552,7 +455,7 @@ } } - buf.append(StringUtil.__LINE_SEPARATOR); + buf.append(__LINE_SEPARATOR); String log = buf.toString(); write(log); @@ -625,16 +528,19 @@ _logDateCache.setTimeZoneID(_logTimeZone); } - if (_filename != null) - { - _fileOut = new RolloverFileOutputStream(_filename,_append,_retainDays,TimeZone.getTimeZone(_logTimeZone),_filenameDateFormat,null); + if (_filename != null) { + File file = new File(_filename); + if( file.exists() && file.length() > sizeLimit ) { + File old = new File(_filename+".old"); + old.delete(); + file.renameTo(old); + } + _out = new FileOutputStream(file,true); _closeOut = true; - LOG.info("Opened " + getDatedFilename()); + LOG.info("Opened " + _filename); } else - _fileOut = System.err; - - _out = _fileOut; + _out = System.err; synchronized(this) { @@ -664,7 +570,7 @@ { LOG.trace("",e); } - if (_out != null && _closeOut) + if (_closeOut) try { _out.close(); @@ -675,7 +581,6 @@ } _out = null; - _fileOut = null; _closeOut = false; _logDateCache = null; _writer = null;