Log Class
- public class Log
extends Object
This class provides some very simple logging interfaces.
Everything is static, so just call Log.info(), etc.
All static methods for this Singleton service.
-
Hierarchy
-
Object
Log
public static void |
-
clearConsole ()
- Sets the consoleMode flag to false stopping logging to
the tty.
|
public static String |
-
currentTime ()
|
public static void |
-
debug (Throwable e)
- Prints a stackTrace for the given exception to error log
|
public static void |
-
debug (Object o, String s)
- Sends string (prepended with class name) to debug log with newline
|
public static void |
-
debug (String s)
- Sends string to debug log with newline
|
public static void |
-
debug (String s, boolean newline)
- Sends string to debug log with optional newline
|
public static void |
-
error (Object o, String s)
- Sends string (prepended with class name) to error log with newline
|
public static void |
-
error (String s)
- Sends string to error log with newline
|
public static void |
-
error (String s, boolean newline)
- Sends string to error log with optional newline
|
public static void |
-
error (Throwable e)
- Prints a stackTrace for the given exception to error log
|
public static void |
-
exception (Throwable e)
- Prints a stackTrace for the given exception to error log
|
public static void |
-
fatal (Throwable e, int exitVal)
- WARNING: calls System.exit() to kill the VM
|
public static void |
-
fatal (String s, int exitVal)
- WARNING: calls System.exit() to kill the VM
|
public static PrintWriter |
-
getPrintWriter ()
- Synchronize on this writer if used in a multi-threaded
environment.
|
public static String |
-
getStackTrace (Throwable e)
|
public static PrintWriter |
-
getStderrWriter ()
- Synchronize on this writer if used in a multi-threaded
environment.
|
public static PrintWriter |
-
getStdoutWriter ()
- Synchronize on this writer if used in a multi-threaded
environment.
|
public static void |
-
info (String s)
- Sends string to info log with newline
|
public static void |
-
info (String s, boolean newline)
- Sends string to info log with optional newline
|
public static void |
-
printCurrentTime (PrintWriter out)
|
public static void |
-
printCurrentTime (PrintWriter out, boolean showThread)
|
public static long |
-
profileFinish (String taskName, long startTime)
- Logs the start, finished, and elapsed time for the given task
For example,
long startTime = Log.profileStart();
...do some stuff...
|
public static long |
-
profileFinish (String taskName, long startTime, long finishTime, boolean verbose)
|
public static long |
-
profileStart ()
|
public static void |
-
setConsole ()
- Sets the console flag to true causing all logging to be
sent to the tty
|
public static void |
-
setConsole (boolean value)
- Sets the consoleMode flag controlling logging to
the tty.
|
public static PrintWriter |
-
setPrintWriter (PrintWriter writer)
- Synchronize on this writer if used in a multi-threaded
environment.
|
public static void |
-
stackTrace ()
- Prints a stackTrace marking the current stack to error log
|
public static void |
-
warn (String s)
- Sends string to warn log with newline
|
public static void |
-
warn (String s, boolean newline)
- Sends string to warn log with optional newline
|
Methods from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
consoleMode
public static boolean consoleMode
- flag for logging to console in addition to log file
logDir
public static String
logDir
- Directory holding log output
logFile
public static String
logFile
- The name of the file holding log output
logWriter
public static PrintWriter
logWriter
- output for stderr console logging
stderrWriter
public static PrintWriter
stderrWriter
- output for stderr console logging
stdoutWriter
public static PrintWriter
stdoutWriter
- output for stdout console logging
T_SEP
public static final String
T_SEP
Log
public Log()
clearConsole() Method
public static void clearConsole()
Sets the consoleMode flag to false stopping logging to
the tty.
currentTime() Method
public static String
currentTime()
Returns
- The current time and thread name formatted for logging
debug(Throwable) Method
public static void debug(Throwable
e)
Prints a stackTrace for the given exception to error log
debug(Object, String) Method
public static void debug(Object
o,
String
s)
Sends string (prepended with class name) to debug log with newline
debug(String) Method
public static void debug(String
s)
Sends string to debug log with newline
debug(String, boolean) Method
public static void debug(String
s,
boolean newline)
Sends string to debug log with optional newline
error(Object, String) Method
public static void error(Object
o,
String
s)
Sends string (prepended with class name) to error log with newline
error(String) Method
public static void error(String
s)
Sends string to error log with newline
error(String, boolean) Method
public static void error(String
s,
boolean newline)
Sends string to error log with optional newline
error(Throwable) Method
public static void error(Throwable
e)
Prints a stackTrace for the given exception to error log
exception(Throwable) Method
public static void exception(Throwable
e)
Prints a stackTrace for the given exception to error log
fatal(Throwable, int) Method
public static void fatal(Throwable
e,
int exitVal)
WARNING: calls System.exit() to kill the VM
fatal(String, int) Method
public static void fatal(String
s,
int exitVal)
WARNING: calls System.exit() to kill the VM
getPrintWriter() Method
public static PrintWriter
getPrintWriter()
Synchronize on this writer if used in a multi-threaded
environment.
getStackTrace(Throwable) Method
public static String
getStackTrace(Throwable
e)
Returns
- String with stack trace information for given exception
getStderrWriter() Method
public static PrintWriter
getStderrWriter()
Synchronize on this writer if used in a multi-threaded
environment.
getStdoutWriter() Method
public static PrintWriter
getStdoutWriter()
Synchronize on this writer if used in a multi-threaded
environment.
info(String) Method
public static void info(String
s)
Sends string to info log with newline
info(String, boolean) Method
public static void info(String
s,
boolean newline)
Sends string to info log with optional newline
printCurrentTime(PrintWriter) Method
public static void printCurrentTime(PrintWriter
out)
printCurrentTime(PrintWriter, boolean) Method
public static void printCurrentTime(PrintWriter
out,
boolean showThread)
profileFinish(String, long) Method
public static long profileFinish(String
taskName,
long startTime)
Logs the start, finished, and elapsed time for the given task
For example,
long startTime = Log.profileStart();
...do some stuff...
Log.profileFinish("MyApp.TaskName", startTime);
Parameters
-
taskName
- A short name for the task -- no spaces
-
startTime
- from profileStart
profileFinish(String, long, long, boolean) Method
public static long profileFinish(String
taskName,
long startTime,
long finishTime,
boolean verbose)
profileStart() Method
public static long profileStart()
Returns
- the startTime used in profileFinish
setConsole() Method
public static void setConsole()
Sets the console flag to true causing all logging to be
sent to the tty
setConsole(boolean) Method
public static void setConsole(boolean value)
Sets the consoleMode flag controlling logging to
the tty.
setPrintWriter(PrintWriter) Method
public static PrintWriter
setPrintWriter(PrintWriter
writer)
Synchronize on this writer if used in a multi-threaded
environment.
stackTrace() Method
public static void stackTrace()
Prints a stackTrace marking the current stack to error log
warn(String) Method
public static void warn(String
s)
Sends string to warn log with newline
warn(String, boolean) Method
public static void warn(String
s,
boolean newline)
Sends string to warn log with optional newline