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.Writer
A 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 int
archive_count
The number of backup archives of log files.private java.io.File
log_file
The log file.private long
log_file_size
Current size of the log file.private long
max_size
The maximum size of the log before it is archived.private java.io.Writer
out
The 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 void
checkLogSize()
Checks the size of the file, and if it has reached or exceeded the maximum limit then archive the log.void
close()
void
flush()
void
write(char[] cbuf, int off, int len)
void
write(int c)
void
write(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.IOException
Constructs 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.IOException
Checks 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:
write
in classjava.io.Writer
- Throws:
java.io.IOException
-
write
public void write(char[] cbuf, int off, int len) throws java.io.IOException
- Specified by:
write
in classjava.io.Writer
- Throws:
java.io.IOException
-
write
public void write(java.lang.String str, int off, int len) throws java.io.IOException
- Overrides:
write
in classjava.io.Writer
- Throws:
java.io.IOException
-
flush
public void flush() throws java.io.IOException
- Specified by:
flush
in interfacejava.io.Flushable
- Specified by:
flush
in classjava.io.Writer
- Throws:
java.io.IOException
-
close
public void close() throws java.io.IOException
- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Specified by:
close
in classjava.io.Writer
- Throws:
java.io.IOException
-
-