edu.byu.ece.edif.tools
Class LogFile

java.lang.Object
  extended by edu.byu.ece.edif.tools.LogFile

public class LogFile
extends java.lang.Object

Encapsulation class for 5 PrintStream objects: Error, Warning, Normal, Logfile, Debug.

Allows the user to specify the verbosity level via the command line. Redirects System.out and System.err to special private class that prints to both the logfile (if any) and the System stream.

The streams can be accessed similar to stdout and stderr. Instead of
System.out.println();
the command is
LogFile.out().println();
This is because Java doesn't support read-only public variables.

Author:
Derrick Gibelyou

Nested Class Summary
(package private)  class LogFile.outStream
          Special Private class that inherit from PrintStream, and overwrites the print methods.
(package private)  class LogFile.tester
           
 
Field Summary
protected  java.io.PrintStream _debug
           
protected  java.io.PrintStream _err
           
protected  java.io.PrintStream _log
           
protected  int _LogLevel
           
protected  java.io.PrintStream _null
          Special anonymous inner class that doesn't write to anything.
protected  java.io.PrintStream _out
           
protected  java.io.PrintStream _warn
           
static int DEBUG
           
static int ERR
           
static int LOG
           
private static LogFile logger
          This is a singleton class.
static int STD
           
protected static java.io.PrintStream stderr
           
protected static java.io.PrintStream stdout
           
static int WARN
           
 
Constructor Summary
private LogFile()
          Default to no log and no debug using a special /dev/nul PrintStream, default to stdout, warning and errors to stderr
 
Method Summary
static void coverLegacyCode()
           
static java.io.PrintStream debug()
           
static java.io.PrintStream err()
           
static LogFile getInstance()
           
static void InitializeLog(java.io.PrintStream debug, java.io.PrintStream log, int log_level)
          Initializes a logfile object
static java.io.PrintStream log()
           
static void main(java.lang.String[] args)
          Prints one thing to each stream, and tests to see if it arrived and didn't arrive appropriately Has some messy code at the moment, but I will clean it up very soon.
static java.io.PrintStream out()
           
static void restoreSystemStreams()
           
private  void setLogs(java.io.PrintStream debug, java.io.PrintStream log, int log_level)
           
private static boolean test(java.lang.String teststr, java.io.PrintStream sut, java.io.BufferedReader readStream, java.io.BufferedReader stdStream, boolean checkSTD)
           
private static void testStreams(java.io.PrintStream out, java.io.PrintStream err)
           
static java.io.PrintStream warn()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

logger

private static LogFile logger
This is a singleton class. However, I need to ensure that the streams are setup to a default, in case somebody tries to print without first setting things up.


DEBUG

public static final int DEBUG
See Also:
Constant Field Values

LOG

public static final int LOG
See Also:
Constant Field Values

STD

public static final int STD
See Also:
Constant Field Values

WARN

public static final int WARN
See Also:
Constant Field Values

ERR

public static final int ERR
See Also:
Constant Field Values

_LogLevel

protected int _LogLevel

stdout

protected static java.io.PrintStream stdout

stderr

protected static java.io.PrintStream stderr

_err

protected java.io.PrintStream _err

_warn

protected java.io.PrintStream _warn

_out

protected java.io.PrintStream _out

_log

protected java.io.PrintStream _log

_debug

protected java.io.PrintStream _debug

_null

protected java.io.PrintStream _null
Special anonymous inner class that doesn't write to anything. This is a platform independent /dev/null

Constructor Detail

LogFile

private LogFile()
Default to no log and no debug using a special /dev/nul PrintStream, default to stdout, warning and errors to stderr

Method Detail

getInstance

public static LogFile getInstance()

debug

public static java.io.PrintStream debug()

log

public static java.io.PrintStream log()

out

public static java.io.PrintStream out()

warn

public static java.io.PrintStream warn()

err

public static java.io.PrintStream err()

testStreams

private static void testStreams(java.io.PrintStream out,
                                java.io.PrintStream err)

InitializeLog

public static void InitializeLog(java.io.PrintStream debug,
                                 java.io.PrintStream log,
                                 int log_level)
Initializes a logfile object

Parameters:
debug: - stream to use for debugging info (can be null)
log: - stream to send logfile info to (can be null)
log_level: - the user specified log level: 1-5. 5 for printing debug to stdout, 1 for only errors to stdout

coverLegacyCode

public static void coverLegacyCode()

restoreSystemStreams

public static void restoreSystemStreams()

setLogs

private void setLogs(java.io.PrintStream debug,
                     java.io.PrintStream log,
                     int log_level)

test

private static boolean test(java.lang.String teststr,
                            java.io.PrintStream sut,
                            java.io.BufferedReader readStream,
                            java.io.BufferedReader stdStream,
                            boolean checkSTD)
                     throws java.lang.Exception
Throws:
java.lang.Exception

main

public static void main(java.lang.String[] args)
                 throws java.io.IOException
Prints one thing to each stream, and tests to see if it arrived and didn't arrive appropriately Has some messy code at the moment, but I will clean it up very soon.

Parameters:
args -
Throws:
java.lang.Exception
java.io.IOException