|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||
java.lang.Objectcom.marringtons.util.Log
Adept provides a simplified logging system where the Sun or log4j classes are overkill. The default log writes to the console - though this can be redirected to wherever is convenient. This is a very simple logging system. If you want permanent logging messages and better logging control, use the Sun or Log4J systems.
Log.message("write a simple message to the log");
Log.error("time stamp, message and stack dump to log", new Exception(
"sample exception"));
Log.error(new Exception("sample exception"));
Log.stamp("time stamp and message to log");
Log.setStream(getOutputStream());
Log.setStream(System.err); // PrintStream
Log.setStream("myFile.log");
Log.dumpStack = false; // suppresses stack dumps (usually for testing where errors expected).
Log.verbose = false; // default is property verbose.logging
Log.verbose("message won't log");
Log.verbose = true;
Log.verbose("message will log");
if (Log.verbose) // save processing arguments that are never used ...
Log.verbose("message " + createMessage() + " that is expensive to build");
Log.setVerbosity(true); // so persists as a property between runs.
While creating junit tests for other classes it is often important to review
log output. There is a method called forJunit() for that purpose. Every time
it is called it resets an in-memory logging buffer after extracting a string
of all log messages since the last call.
Log.forJunit(); ... String logMessages = Log.forJunit();
Application| Field Summary | |
static boolean |
dumpStack
Used to reduce display on expected errors - only used by unit tests. |
static boolean |
verbose
Set to true to see more information on program operation - for production level fault finding. |
| Constructor Summary | |
Log()
|
|
| Method Summary | |
static void |
debug(Object message)
Method debug - write a timestamped message to the application log file. |
static String |
error(Object message)
Used to log errors. |
static String |
error(Object message,
Throwable throwable)
Used to log errors. |
static String |
error(Throwable throwable)
Used to log errors. |
static String |
forJunit()
Set log for Junit testing by recording log output to a string and returning it on demand. |
static void |
message(Object message)
write a message to the application log file. |
static void |
resetStream()
Restore the stream to the console. |
static void |
setStream(OutputStream stream)
Logging goes to the console by default. |
static void |
setStream(PrintStream stream)
Logging goes to the console by default. |
static void |
setStream(String name)
Logging goes to the console by default. |
static void |
setVerbosity(boolean verbosity)
In Verbose mode get more logging messages - for production debugging. |
static String |
stamp()
Send timestamp to log (yyy7mmdd-hh:mm.sss). |
static String |
stamp(Object message)
Add a timestamped message line to the log. |
static void |
verbose(String string)
Only log if verbose mode is on. |
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
public static boolean dumpStack
public static boolean verbose
if (Log.verbose) Log.verbose( "message "+createMessage()+" that is expensive to build");
setVerbosity(boolean)| Constructor Detail |
public Log()
| Method Detail |
public static void message(Object message)
message - to write
public static String error(Object message,
Throwable throwable)
message - to display - IMPORTANT to provide context informationthrowable - display exception info and stack dump
public static String error(Throwable throwable)
throwable - Exception that caused the error
public static String error(Object message)
message - to display - IMPORTANT to provide context information (what where and why).
public static String stamp()
public static String stamp(Object message)
message - to write to log.
public static void resetStream()
Log.forJunit(); ... String logResult = Log.forJunit(); Log.resetStream();
public static void setStream(OutputStream stream)
stream - to write log messages to.public static void setStream(PrintStream stream)
Log.setStream( System.err);
stream - to write log messages to.public static void setStream(String name)
name - of file to write log messages to.public static void debug(Object message)
message - to write
public static void setVerbosity(boolean verbosity)
throws FileNotFoundException
verbosity - true to display verbose messages.
FileNotFoundException - because we record the configuration changeverbosepublic static void verbose(String string)
string - message to write if verbose logging is on.public static String forJunit()
|
|||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||||