Package hec.io
Class HecSwappingOutputStream
java.lang.Object
java.io.OutputStream
hec.io.HecSwappingOutputStream
- All Implemented Interfaces:
Closeable
,Flushable
,AutoCloseable
static class to print data to a file and to stdout swapping logfiles when they
reach a user specified maximum size. The user also specifies how many
log files to swap between.
Properties can be set through the following properties:
logfile.name - String. name of the log file. Default is /tmp/jre.out
logfile.count - int. number of logfiles to swap between. Default is 2
logfile.size - int. size logfile will grow to before swapping. Default is 51200 bytes
logfile.print - boolean. whether to echo System.out messages to stdout. Default is false.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionvoid
close()
Closes this file output stream and releases any system resources associated with this stream.get the name of the log file current being written tostatic HecSwappingOutputStream
return the current HecSwappingOutputStream, if one hasn't been created then create it with the System properties or defaults if the system properties are not set.static HecSwappingOutputStream
getOutputStream
(String name, int numLogs, int logSize, boolean toConsole) return the current HecSwappingOutputStream, if one hasn't been created then create it with the specified arguments.void
write
(byte[] b) Writes b.length bytes from the specified byte array to this file output stream.void
write
(byte[] b, int off, int len) Writes len bytes from the specified byte array starting at offset off to this file output stream.void
write
(int b) Writes the specified byte to this file output stream.Methods inherited from class java.io.OutputStream
flush, nullOutputStream
-
Field Details
-
_logFileNames
-
_logFileName2
-
_logFileSize
protected long _logFileSize -
_currentLogFileName
protected int _currentLogFileName
-
-
Method Details
-
getOutputStream
public static HecSwappingOutputStream getOutputStream(String name, int numLogs, int logSize, boolean toConsole) throws IOException return the current HecSwappingOutputStream, if one hasn't been created then create it with the specified arguments.- Parameters:
name
- - name of logfile.numLogs
- - number of logfile to maintain.logSize
- - max size of log file before swapping to next logfile. 0 means no swapping- Throws:
IOException
-
getOutputStream
return the current HecSwappingOutputStream, if one hasn't been created then create it with the System properties or defaults if the system properties are not set.- Throws:
IOException
-
getLogFileName
get the name of the log file current being written to -
close
Closes this file output stream and releases any system resources associated with this stream.- Specified by:
close
in interfaceAutoCloseable
- Specified by:
close
in interfaceCloseable
- Overrides:
close
in classOutputStream
- Throws:
IOException
-
write
Writes b.length bytes from the specified byte array to this file output stream.- Overrides:
write
in classOutputStream
- Throws:
IOException
-
write
Writes len bytes from the specified byte array starting at offset off to this file output stream.- Overrides:
write
in classOutputStream
- Throws:
IOException
-
write
Writes the specified byte to this file output stream.- Specified by:
write
in classOutputStream
- Throws:
IOException
-