Package com.mckoi.util
Class LogWriter
- java.lang.Object
-
- java.io.Writer
-
- com.mckoi.util.LogWriter
-
- All Implemented Interfaces:
java.io.Closeable,java.io.Flushable,java.lang.Appendable,java.lang.AutoCloseable
public class LogWriter extends java.io.WriterA Writer that writes information to a log file that archives old log entries when it goes above a certain size.
-
-
Field Summary
Fields Modifier and Type Field Description private intarchive_countThe number of backup archives of log files.private java.io.Filelog_fileThe log file.private longlog_file_sizeCurrent size of the log file.private longmax_sizeThe maximum size of the log before it is archived.private java.io.WriteroutThe log file FileWriter.
-
Constructor Summary
Constructors Constructor Description LogWriter(java.io.File base_name, long max_size, int archive_count)Constructs the log writer.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidcheckLogSize()Checks the size of the file, and if it has reached or exceeded the maximum limit then archive the log.voidclose()voidflush()voidwrite(char[] cbuf, int off, int len)voidwrite(int c)voidwrite(java.lang.String str, int off, int len)
-
-
-
Field Detail
-
log_file
private final java.io.File log_file
The log file.
-
max_size
private final long max_size
The maximum size of the log before it is archived.
-
archive_count
private final int archive_count
The number of backup archives of log files.
-
log_file_size
private long log_file_size
Current size of the log file.
-
out
private java.io.Writer out
The log file FileWriter.
-
-
Constructor Detail
-
LogWriter
public LogWriter(java.io.File base_name, long max_size, int archive_count) throws java.io.IOExceptionConstructs the log writer. The 'base_name' is the name of log file. 'max_size' is the maximum size the file can grow to before it is copied to a log archive.- Throws:
java.io.IOException
-
-
Method Detail
-
checkLogSize
private void checkLogSize() throws java.io.IOExceptionChecks the size of the file, and if it has reached or exceeded the maximum limit then archive the log.- Throws:
java.io.IOException
-
write
public void write(int c) throws java.io.IOException- Overrides:
writein classjava.io.Writer- Throws:
java.io.IOException
-
write
public void write(char[] cbuf, int off, int len) throws java.io.IOException- Specified by:
writein classjava.io.Writer- Throws:
java.io.IOException
-
write
public void write(java.lang.String str, int off, int len) throws java.io.IOException- Overrides:
writein classjava.io.Writer- Throws:
java.io.IOException
-
flush
public void flush() throws java.io.IOException- Specified by:
flushin interfacejava.io.Flushable- Specified by:
flushin classjava.io.Writer- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException- Specified by:
closein interfacejava.lang.AutoCloseable- Specified by:
closein interfacejava.io.Closeable- Specified by:
closein classjava.io.Writer- Throws:
java.io.IOException
-
-