java.lang.Object
org.eclipse.jetty.util.component.AbstractLifeCycle
net.i2p.jetty.I2PRequestLog
- All Implemented Interfaces:
RequestLog, LifeCycle
This
RequestLog implementation outputs logs in the pseudo-standard NCSA common log format. Configuration options allow a choice between the standard Common Log Format (as used in the 3 log format) and the Combined Log Format (single log format). This log format can be output by most web servers, and almost all web log analysis software can understand these formats. ** I2P Mods ** For Jetty 5, this extended NCSARequestLog to override log() to put in the requestor's destination hash, instead of 127.0.0.1, which is placed in the X-I2P-DestHash field in the request headers by I2PTunnelHTTPServer. But we also had to modify NCSARequestLog to do so, to change private fields to protected. So that we will work with system Jetty 6 packages, we just copy the whole thing and modify log() as required.Nested Class Summary
Nested classes/interfaces inherited from class AbstractLifeCycle
AbstractLifeCycle.AbstractLifeCycleListenerNested classes/interfaces inherited from interface LifeCycle
LifeCycle.ListenerField Summary
FieldsModifier and TypeFieldDescriptionprivate booleanTrue to append to an existing log file.private booleanTrue to write the log entries base64 encoded.private ArrayList<Utf8StringBuilder> Buffers holding the log entry fields.private booleanTrue to log a final entry when closing.private char[]Scratch buffer for copying between buffers.private booleanTrue for the extended log format.private StringFile name of the request log.private StringDate format appended to the log file name.private OutputStreamThe underlying file stream.private PathMappings<String> Mappings of the ignored request paths.private String[]Request paths excluded from the log.private booleanTrue to log the request cookies.private DateCacheCache of the formatted request dates.private StringDate format of the log entries.private booleanTrue to log the request latency.private LocaleLocale used for the log dates.private booleanTrue to log the server name and port.private StringTime zone of the log dates.private OutputStreamStream the log entries are written to.private booleanTrue to prefer the proxied remote address.private intDays of rotated log files kept.private WriterWriter for the formatted log entries.Fields inherited from class AbstractLifeCycle
FAILED, RUNNING, STARTED, STARTING, STOP_ON_FAILURE, STOPPED, STOPPINGConstructor Summary
ConstructorsConstructorDescriptionI2PRequestLog.I2PRequestLog(String filename) Create a request log writing to the named file.Method Summary
Public MethodsModifier and TypeMethodDescriptionprotected voiddoStart()Open the log file and build the timestamp cache.protected voiddoStop()Flush and close the log file.The log filename with any date tokens expanded.The file the log is currently writing to.The date pattern used to name rotated files.String[]The request paths left out of the log.booleanWhether cookie headers are recorded.The format used to timestamp each entry.booleanWhether request latency is recorded.The locale timestamps are rendered in.booleanWhether the server identity is recorded in each entry.The time zone timestamps are rendered in.intHow many days of rotated logs are kept.booleanisAppend()Whether output is appended to an existing file rather than replacing it.booleanWhether the extended, combined log format is in use.voidWrite one request out in the configured format.protected voidlogExtended(Request request, Writer writer) Write the extended fields: the referrer and the user agent.voidsetAppend(boolean append) Choose whether output appends to or replaces an existing file.voidsetB64(boolean b64) Choose the base used to encode destination hashes in the log.voidsetExtended(boolean extended) Select the extended, combined log format.voidsetFilename(String filename) Redirect the log to another file.voidsetFilenameDateFormat(String logFileDateFormat) Set the log file date format.voidsetIgnorePaths(String[] ignorePaths) Set the request paths to leave out of the log.voidsetLogCookies(boolean logCookies) Record whether cookie headers are logged.voidsetLogDateFormat(String format) If not set, the pre-formated request timestamp is used.voidsetLogLatency(boolean logLatency) Record whether request latency is logged.voidsetLogLocale(Locale logLocale) Set the locale timestamps are rendered in.voidsetLogServer(boolean logServer) Record whether the server field is logged.voidsetLogTimeZone(String tz) Set the time zone timestamps are rendered in.voidsetPreferProxiedForAddress(boolean preferProxiedForAddress) Record whether proxied destinations are preferred for an address.voidsetRetainDays(int retainDays) Set how many days of rotated logs are kept.Methods inherited from class AbstractLifeCycle
addLifeCycleListener, getState, getState, getStopTimeout, isFailed, isRunning, isStarted, isStarting, isStopped, isStopping, removeLifeCycleListener, setStopTimeout, start, stop
Field Details
_filename
File name of the request log._extended
private boolean _extendedTrue for the extended log format._append
private boolean _appendTrue to append to an existing log file._retainDays
private int _retainDaysDays of rotated log files kept._closeOut
private boolean _closeOutTrue to log a final entry when closing._preferProxiedForAddress
private boolean _preferProxiedForAddressTrue to prefer the proxied remote address._logDateFormat
Date format of the log entries._filenameDateFormat
Date format appended to the log file name._logLocale
Locale used for the log dates._logTimeZone
Time zone of the log dates._ignorePaths
Request paths excluded from the log._logLatency
private boolean _logLatencyTrue to log the request latency._logCookies
private boolean _logCookiesTrue to log the request cookies._logServer
private boolean _logServerTrue to log the server name and port._b64
private boolean _b64True to write the log entries base64 encoded._out
Stream the log entries are written to._fileOut
The underlying file stream._logDateCache
Cache of the formatted request dates._ignorePathMap
Mappings of the ignored request paths._writer
Writer for the formatted log entries._buffers
Buffers holding the log entry fields._copy
private transient char[] _copyScratch buffer for copying between buffers.
Constructor Details
I2PRequestLog
public I2PRequestLog()I2PRequestLog.I2PRequestLog
Create a request log writing to the named file.- Parameters:
filename- the file to write to, in any formatRolloverFileOutputStreamaccepts
Method Details
setFilename
Redirect the log to another file.- Parameters:
filename- the file to write to, in any formatRolloverFileOutputStreamaccepts; null is ignored
getFilename
getDatedFilename
The log filename with any date tokens expanded.- Returns:
- the filename in use right now, or the undated name when the log is not rolling over
setLogDateFormat
If not set, the pre-formated request timestamp is used.- Parameters:
format- Format for the timestamps in the log file.
getLogDateFormat
The format used to timestamp each entry.- Returns:
- the date format, or null to use the timestamp jetty already formatted
setLogLocale
Set the locale timestamps are rendered in.- Parameters:
logLocale- the locale, or null for the platform default
getLogLocale
The locale timestamps are rendered in.- Returns:
- the locale, or null for the platform default
setLogTimeZone
Set the time zone timestamps are rendered in.- Parameters:
tz- the time zone ID, or null for the platform default
getLogTimeZone
The time zone timestamps are rendered in.- Returns:
- the time zone ID, or null for the platform default
setRetainDays
public void setRetainDays(int retainDays) Set how many days of rotated logs are kept.- Parameters:
retainDays- the retention period in days
getRetainDays
public int getRetainDays()How many days of rotated logs are kept.- Returns:
- the retention period in days
setExtended
public void setExtended(boolean extended) Select the extended, combined log format.- Parameters:
extended- true for the extended format
isExtended
public boolean isExtended()Whether the extended, combined log format is in use.- Returns:
- true when the extended format is selected
setAppend
public void setAppend(boolean append) Choose whether output appends to or replaces an existing file.- Parameters:
append- true to append
isAppend
public boolean isAppend()Whether output is appended to an existing file rather than replacing it.- Returns:
- true when appending
setIgnorePaths
Set the request paths to leave out of the log.- Parameters:
ignorePaths- the paths to exclude, or null to log everything
getIgnorePaths
The request paths left out of the log.- Returns:
- the ignored paths, or null when nothing is excluded
setLogCookies
public void setLogCookies(boolean logCookies) Record whether cookie headers are logged.- Parameters:
logCookies- true to log cookies
getLogCookies
public boolean getLogCookies()Whether cookie headers are recorded.- Returns:
- true when cookies are logged
getLogServer
public boolean getLogServer()Whether the server identity is recorded in each entry.- Returns:
- true when the server field is logged
setLogServer
public void setLogServer(boolean logServer) Record whether the server field is logged.- Parameters:
logServer- true to log the server identity
setLogLatency
public void setLogLatency(boolean logLatency) Record whether request latency is logged.- Parameters:
logLatency- true to log latency
getLogLatency
public boolean getLogLatency()Whether request latency is recorded.- Returns:
- true when latency is logged
setPreferProxiedForAddress
public void setPreferProxiedForAddress(boolean preferProxiedForAddress) Record whether proxied destinations are preferred for an address.- Parameters:
preferProxiedForAddress- true to prefer the proxied destination
setB64
public void setB64(boolean b64) Choose the base used to encode destination hashes in the log.- Parameters:
b64- true to log in base 64, false for base 32
log
Write one request out in the configured format.- Specified by:
login interfaceRequestLog- Parameters:
request- the request being loggedresponse- the response being logged
logExtended
Write the extended fields: the referrer and the user agent.- Parameters:
request- the request being loggedwriter- where the log entry is written- Throws:
IOException- if the writer fails
doStart
Open the log file and build the timestamp cache.- Overrides:
doStartin classAbstractLifeCycle- Throws:
Exception- if the log file cannot be opened
doStop
Flush and close the log file.- Overrides:
doStopin classAbstractLifeCycle- Throws:
Exception- if the log file cannot be closed
getFilenameDateFormat
The date pattern used to name rotated files.- Returns:
- the filename date format
setFilenameDateFormat
Set the log file date format. See RolloverFileOutputStream(String, boolean, int, TimeZone, String, String) Set the date pattern used to name rotated files.- Parameters:
logFileDateFormat- the pattern passed to RolloverFileOutputStream