java.lang.Object
net.i2p.util.LogWriter
net.i2p.util.FileLogWriter
- All Implemented Interfaces:
Runnable
File-based log writer thread that pulls log records from the LogManager, writes them to the current logfile, and rotates the logs as necessary.
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static classGzips a rotated log file in the background.Field Summary
FieldsModifier and TypeFieldDescriptionprivate FileThe file being written now.private WriterThe writer for the current log file, volatile as it changes on rotation.private intDisk full errors logged so far.private booleanTrue to make the log files group readable.private longBytes written to the current file.private intNumber of the current rotation.private static final intMost disk full errors logged.Fields inherited from class LogWriter
_manager, _write, FLUSH_INTERVALModifier and TypeFieldDescriptionprotected final LogManagerThe log manager owning this writer and its context.protected booleanWhether the writer should continue writing.(package private) static final longAjax refresh interval.Constructor Summary
ConstructorsConstructorDescriptionFileLogWriter(LogManager manager) Creates a writer that drains log records to rotating files on disk.Method Summary
Modifier and TypeMethodDescriptionprotected voidClose the log file writer.private voidcloseWriter(File currentFile, boolean threadGzipper) Gzip the closed file.File may not exist or have old logs in it if not opened yet.protected voidFlush the log file writer.private FilegetFirstFile(File base, String pattern, int max) Retrieve the first file, updating the rotation number accordinglyprivate FileNext file in the rotation.(package private) static booleanisGroupTraversable(File dir) Whether the group can traverse (search) an existing directory.private static final StringPuts the rotation number into the file name.private voidRotate to the next file (or the first file if this is the first call)protected voidwriteRecord(int priority, String val) Write the formatted record text at the given priority.protected voidwriteRecord(LogRecord rec, String formatted) Write the record and its formatted text, using the record's priority.Methods inherited from class LogWriter
flushRecords, flushRecords, run, setFlushInterval, stopWriting, wakeupModifier and TypeMethodDescriptionvoidFlush pending log records.voidflushRecords(boolean shouldWait) Flush pending log records, optionally waiting for new ones.voidrun()Write loop, flushing records and rereading config until stopped.voidsetFlushInterval(long interval) Flush interval for the log writer, clamped to the supported range.voidStop the log writer thread.voidwakeup()Wake up the writer to immediately re-read config and flush pending records.
Field Details
_currentOut
The writer for the current log file, volatile as it changes on rotation._rotationNum
private int _rotationNumNumber of the current rotation._currentFile
The file being written now._numBytesInCurrentFile
private long _numBytesInCurrentFileBytes written to the current file._groupReadable
private boolean _groupReadableTrue to make the log files group readable.MAX_DISKFULL_MESSAGES
private static final int MAX_DISKFULL_MESSAGESMost disk full errors logged.- See Also:
_diskFullMessageCount
private int _diskFullMessageCountDisk full errors logged so far.
Constructor Details
FileLogWriter
Creates a writer that drains log records to rotating files on disk.- Parameters:
manager- the LogManager this writer drains records from; its configuration supplies the log directory and rotation settings
Method Details
currentFile
File may not exist or have old logs in it if not opened yet.- Specified by:
currentFilein classLogWriter- Returns:
- non-null
isGroupTraversable
Whether the group can traverse (search) an existing directory. Group execute on the directory is what allows a group-readable file inside it to be opened, so this is the check that decides whether group-readable log files are actually reachable.- Parameters:
dir- the directory to test- Returns:
- true if the group has execute/search permission, or if permissions cannot be determined
writeRecord
Write the record and its formatted text, using the record's priority.- Specified by:
writeRecordin classLogWriter- Parameters:
rec- the LogRecord to write.formatted- a String pre-formatted from rec, may be ignored.
writeRecord
Write the formatted record text at the given priority.- Specified by:
writeRecordin classLogWriter- Parameters:
priority- the level to log the line at.val- the String to write.
flushWriter
closeWriter
closeWriter
Gzip the closed file.- Parameters:
currentFile- the log file just closed, gzipped if it is large enoughthreadGzipper- if true, spin off a thread
rotateFile
private void rotateFile()Rotate to the next file (or the first file if this is the first call)Caller must synch.
getNextFile
getFirstFile
Retrieve the first file, updating the rotation number accordinglyCaller must synch.
- Parameters:
base- the log directory the file name is resolved against, null if the pattern is a full pathpattern- the file name pattern where each # or @ is replaced by the rotation numbermax- the maximum number of rotation files- Returns:
- the first rotation file that does not exist yet, or the oldest one if all of them exist
replace