Package org.eclipse.jetty.util
Class RolloverFileOutputStream
java.lang.Object
java.io.OutputStream
org.eclipse.jetty.util.RolloverFileOutputStream
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
RolloverFileOutputStream.
This output stream puts content in a file that is rolled over every 24 hours. The filename must include the string "yyyy_mm_dd", which is replaced with the actual date when creating and rolling over the file.
Old files are retained for a number of days before being deleted.
-
Nested Class Summary
Nested Classes -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate static Timer
private boolean
private File
private SimpleDateFormat
private SimpleDateFormat
private String
private OutputStream
private int
(package private) static final String
(package private) static final String
(package private) static final int
(package private) static final String
-
Constructor Summary
ConstructorsConstructorDescriptionRolloverFileOutputStream
(String filename) RolloverFileOutputStream
(String filename, boolean append) RolloverFileOutputStream
(String filename, boolean append, int retainDays) RolloverFileOutputStream
(String filename, boolean append, int retainDays, TimeZone zone) RolloverFileOutputStream
(String filename, boolean append, int retainDays, TimeZone zone, String dateFormat, String backupFormat) RolloverFileOutputStream
(String filename, boolean append, int retainDays, TimeZone zone, String dateFormat, String backupFormat, ZonedDateTime now) -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
void
flush()
int
(package private) void
private void
renameFile
(File src, File dest) protected void
This method is called whenever a log file is rolled overprivate void
(package private) void
setFile
(ZonedDateTime now) static ZonedDateTime
toMidnight
(ZonedDateTime now) Get the "start of day" for the provided DateTime at the zone specified.void
write
(byte[] buf) void
write
(byte[] buf, int off, int len) void
write
(int b) Methods inherited from class java.io.OutputStream
nullOutputStream
-
Field Details
-
__rollover
-
YYYY_MM_DD
- See Also:
-
ROLLOVER_FILE_DATE_FORMAT
- See Also:
-
ROLLOVER_FILE_BACKUP_FORMAT
- See Also:
-
ROLLOVER_FILE_RETAIN_DAYS
static final int ROLLOVER_FILE_RETAIN_DAYS- See Also:
-
_out
-
_rollTask
-
_fileBackupFormat
-
_fileDateFormat
-
_filename
-
_file
-
_append
private boolean _append -
_retainDays
private int _retainDays
-
-
Constructor Details
-
RolloverFileOutputStream
- Parameters:
filename
- The filename must include the string "yyyy_mm_dd", which is replaced with the actual date when creating and rolling over the file.- Throws:
IOException
- if unable to create output
-
RolloverFileOutputStream
- Parameters:
filename
- The filename must include the string "yyyy_mm_dd", which is replaced with the actual date when creating and rolling over the file.append
- If true, existing files will be appended to.- Throws:
IOException
- if unable to create output
-
RolloverFileOutputStream
- Parameters:
filename
- The filename must include the string "yyyy_mm_dd", which is replaced with the actual date when creating and rolling over the file.append
- If true, existing files will be appended to.retainDays
- The number of days to retain files before deleting them. 0 to retain forever.- Throws:
IOException
- if unable to create output
-
RolloverFileOutputStream
public RolloverFileOutputStream(String filename, boolean append, int retainDays, TimeZone zone) throws IOException - Parameters:
filename
- The filename must include the string "yyyy_mm_dd", which is replaced with the actual date when creating and rolling over the file.append
- If true, existing files will be appended to.retainDays
- The number of days to retain files before deleting them. 0 to retain forever.zone
- the timezone for the output- Throws:
IOException
- if unable to create output
-
RolloverFileOutputStream
public RolloverFileOutputStream(String filename, boolean append, int retainDays, TimeZone zone, String dateFormat, String backupFormat) throws IOException - Parameters:
filename
- The filename must include the string "yyyy_mm_dd", which is replaced with the actual date when creating and rolling over the file.append
- If true, existing files will be appended to.retainDays
- The number of days to retain files before deleting them. 0 to retain forever.zone
- the timezone for the outputdateFormat
- The format for the date file substitution. The default is "yyyy_MM_dd". If set to the empty string, the file is rolledover to the same filename, with the current file being renamed to the backup filename.backupFormat
- The format for the file extension of backup files. The default is "HHmmssSSS".- Throws:
IOException
- if unable to create output
-
RolloverFileOutputStream
RolloverFileOutputStream(String filename, boolean append, int retainDays, TimeZone zone, String dateFormat, String backupFormat, ZonedDateTime now) throws IOException - Throws:
IOException
-
-
Method Details
-
toMidnight
Get the "start of day" for the provided DateTime at the zone specified.- Parameters:
now
- the date time to calculate from- Returns:
- start of the day of the date provided
-
scheduleNextRollover
-
getFilename
-
getDatedFilename
-
getRetainDays
public int getRetainDays() -
setFile
- Throws:
IOException
-
renameFile
- Throws:
IOException
-
rollover
This method is called whenever a log file is rolled over- Parameters:
oldFile
- The original filename or null if this is the first creationbackupFile
- The backup filename or null if the filename is dated.newFile
- The new filename that is now being used for logging
-
removeOldFiles
-
write
- Specified by:
write
in classOutputStream
- Throws:
IOException
-
write
- Overrides:
write
in classOutputStream
- Throws:
IOException
-
write
- Overrides:
write
in classOutputStream
- Throws:
IOException
-
flush
- Specified by:
flush
in interfaceFlushable
- Overrides:
flush
in classOutputStream
- Throws:
IOException
-
close
- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classOutputStream
- Throws:
IOException
-