/**
* tracer.java
*
* writes trace info to a PrintWriter, a PrintStream,
* and / or a File. Allows application to write to stdout
* in batch mode or to http output for a servlet.
*
*
* This module is part of Karl Brown's MIDI programming project.
*
*/
package MidiApps;
import java.io.*;
import java.util.*;
/**
*
* @author Karl Brown
* @version 1.0
* last updated 2/16/2003
*/
public class tracer {
static PrintWriter pw = null; // for servlet http output stream
static PrintStream ps = null; // for standard out
static String fname = null; // for file
static File f = null;
static FileWriter fw = null;
static int patch;
static String name;
public static void setPrintWriter(PrintWriter pwIn) {
pw = pwIn;
}
public static void setPrintStream(PrintStream psIn) {
ps = psIn;
}
public static void setFile(String name) {
try {
fname = name;
f = new File(fname);
fw = new FileWriter(f,false);
fw.write("File created: " + fname +"\n");
// fw.close();
trace("File created: " + fname +"\n");
}
catch(Exception e)
{
trace("tracer::setFile: Exception caught:");
trace(e.toString() + "
");
} //catch
}
public static void close() {
try{
if (pw != null) {
pw.println("closing print writer
");
pw.flush();
pw.close();
}
if (ps != null) {
ps.println("closing print stream");
ps.close();
}
if (fw != null) {
fw.write("closing trace file \n");
fw.flush();
fw.close();
}
}
catch(Exception e)
{
trace("tracer::close: Exception caught:");
trace(e.toString());
} //catch
}
/**
*
* Write the input string to stdout, http output,
* and / or file
*
*/
public static void trace(String traceIn) {
try{
if (pw != null) {
pw.println(traceIn + "
");
pw.flush();
}
if (ps != null) {
ps.println(traceIn);
}
if (fw != null) {
fw.write(traceIn + "\n");
fw.flush();
}
}
catch(Exception e)
{
trace("tracer::trace: Exception caught:");
trace(e.toString() + "
");
} //catch
}
public static void print(String printIn) {
try{
if (pw != null) {
pw.println(printIn);
pw.flush();
}
if (ps != null) {
ps.println(printIn);
}
if (fw != null) {
fw.write(printIn + "\n");
fw.flush();
}
}
catch(Exception e)
{
trace("tracer::print: Exception caught:");
trace(e.toString());
} //catch
}
}