public class ConsoleLogger
extends java.io.OutputStream
@SuppressWarnings({"unused", "resource"}) ConsoleLogger logger = new ConsoleLogger("log.txt");
Modifier and Type | Field and Description |
---|---|
(package private) java.io.OutputStream |
console
Default Console output stream.
|
(package private) java.io.OutputStream |
logFile
Output Stream, like a file, to duplicate the console output.
|
Constructor and Description |
---|
ConsoleLogger(java.lang.String fileName)
We have to just create an object of this class and pass the filename
where the log should be written.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
When closing the console, also close the log file.
|
void |
flush()
When flushing the text to the console also flush to the log file.
|
void |
write(byte[] b)
When writing to console also write the the Log File.
|
void |
write(byte[] b,
int off,
int len)
When writing to console also write the the log file.
|
void |
write(int arg0)
When writing to console also write the the Log File.
|
java.io.OutputStream console
java.io.OutputStream logFile
public ConsoleLogger(java.lang.String fileName)
fileName
- Output File where the console should be written.public void write(int arg0) throws java.io.IOException
write
in class java.io.OutputStream
java.io.IOException
OutputStream.write(int)
public void write(byte[] b) throws java.io.IOException
write
in class java.io.OutputStream
java.io.IOException
OutputStream.write(byte[])
public void write(byte[] b, int off, int len) throws java.io.IOException
write
in class java.io.OutputStream
java.io.IOException
OutputStream.write(byte[], int, int)
public void close() throws java.io.IOException
close
in interface java.io.Closeable
close
in interface java.lang.AutoCloseable
close
in class java.io.OutputStream
java.io.IOException
OutputStream.close()
public void flush() throws java.io.IOException
flush
in interface java.io.Flushable
flush
in class java.io.OutputStream
java.io.IOException
OutputStream.flush()