Class Log

java.lang.Object
  |
  +--Log

public class Log
extends java.lang.Object

A general 'logger' or 'tracer' class that logs data into a file.

Here is a sample of it's usage:
public class LogTest {
        public LogTest() {
                Log.open("c:\project\ErrorStream.log", "err");
                Log.open("c:\project\StandardStream.log", "std");
                Log.open("c:\prod.output", "out");
                this.testLog();
                Log.close("err");
                Log.close();
        }

        public void testLog() {
                Log.log("err", "This is an error Test.", false);
                Log.log("std", "This is a standard test.");
                Log.log("This will also output to standard since it was last opened and written to.");
                Log.log("out", "This is to output.");
                Log.log("Now this will write to the out stream.");
        }
}
 


Field Summary
static java.lang.String lastStream
          Stores the last open stream for quick logging.
static java.util.Map openFiles
          Map of all open streams.
 
Constructor Summary
Log()
           
 
Method Summary
static void close()
          Closes the iostream for a all log files.
static void close(java.lang.String name)
          Closes the iostream for a specific log file.
static boolean log(java.lang.Object input)
          Lazy man's log method, logs to the last open stream, new line by default.
static boolean log(java.lang.String name, java.lang.Object input)
          Default log method, creates new line for each input.
static boolean log(java.lang.String name, java.lang.Object input, boolean nl)
          Logs input into file only if it is open.
static void open(java.lang.String file, java.lang.String name)
          Opens a file to write into.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

openFiles

public static java.util.Map openFiles
Map of all open streams.


lastStream

public static java.lang.String lastStream
Stores the last open stream for quick logging.

Constructor Detail

Log

public Log()
Method Detail

open

public static void open(java.lang.String file,
                        java.lang.String name)
Opens a file to write into.

Parameters:
file - the actualy path of the file that this log will write to.
name - the simple name that this specific log will be referenced by.

log

public static boolean log(java.lang.String name,
                          java.lang.Object input,
                          boolean nl)
Logs input into file only if it is open. Sets the current stream to that of name.

Parameters:
name - the name of a file stream to log to.
input - the object input to log.
nl - whether to write a 'new line' to end of line or not.
Returns:
whether the log was successful or not. The only occurance that will cause the logger to return false is if the log ('name') has not been opened before hand.

log

public static boolean log(java.lang.String name,
                          java.lang.Object input)
Default log method, creates new line for each input. Sets the current stream to that of name.

Parameters:
name - the name of a file stream to log to.
input - the object input to log.
Returns:
whether the log was successful or not. The only occurance that will cause the logger to return false is if the log ('name') has not been opened before hand.

log

public static boolean log(java.lang.Object input)
Lazy man's log method, logs to the last open stream, new line by default.


close

public static void close()
Closes the iostream for a all log files.


close

public static void close(java.lang.String name)
Closes the iostream for a specific log file.

Parameters:
name - the name of the log to close.