Methods Summary |
---|
public static void | main(java.lang.String[] args)
try
{
// Start capturing characters
//into the log file.
Tee.start("log.txt");
// Test it.
System.out.println(
"Here's is some stuff to stdout.");
System.err.println(
"Here's is some stuff to stderr.");
System.out.println(
"Let's throw an exception...");
new Exception().printStackTrace();
}
catch (Exception e)
{
e.printStackTrace();
}
finally
{
// Stop capturing characters
//into the log file
// and restore old setup.
Tee.stop();
}
|
public static void | start(java.lang.String f)
// Save old settings.
oldStdout = System.out;
oldStderr = System.err;
// Create/Open logfile.
logfile = new PrintStream(new BufferedOutputStream(new FileOutputStream(f)));
// Start redirecting the output.
System.setOut(new Tee(System.out));
System.setErr(new Tee(System.err));
|
public static void | stop()
System.setOut(oldStdout);
System.setErr(oldStderr);
try
{
logfile.close();
}
catch (Exception e)
{
e.printStackTrace();
}
|
public void | write(int b)
try
{
logfile.write(b);
}
catch (Exception e)
{
e.printStackTrace();
setError();
}
super.write(b);
|
public void | write(byte[] buf, int off, int len)
try
{
logfile.write(buf, off, len);
}
catch (Exception e)
{
e.printStackTrace();
setError();
}
super.write(buf, off, len);
|