|
Forward Computing and Control Pty. Ltd. Logging Package V1.3.0 2004/11/22 |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectjava.io.OutputStream
java.io.FilterOutputStream
java.io.PrintStream
au.com.forward.logging.LogStdStreams
public class LogStdStreams
Redirects System.Err and optionally System.Out to an output file This
catches any uncaught exception traces. A heading can be written to the top
of the file. Autoflush is set so ensure last error saved to disk Each
application invocation appends to the log file.
Use this class is you are using Log4J or some other non-Java logging package.
If you are using standard Java logging then consider using
Logging.initializeLogging(String, String ,boolean, int)
instead
To initialize this class add the following code to your main application class
import au.com.forward.logging.*;
static {
// put all log files in user's home dir
String userHome = System.getProperty("user.home",".")
+System.getProperty("file.separator","/");
// use current dir if cannot find user home
// set up logging for errors etc
// throws RuntimeException if cannot open log file
LogStdStreams.initializeErrorLogging(userHome+"applicationLog.log",
"Log File for Application "+ new Date(),
true, true);
// redirect System.out as well as err and append to existing log
}
Then in the body of the code any statements like
System.err.println(" Error message ..");
System.out.println(" Output ... ");
will be sent to the log file and not sent to the terminal window.
Field Summary |
---|
Fields inherited from class java.io.FilterOutputStream |
---|
out |
Method Summary | |
---|---|
static java.lang.String |
getLogFileName()
Get the name of the logfile |
static java.io.PrintStream |
getLogStream()
Get the PrintStream being used for this logfile |
static void |
initializeErrorLogging(java.lang.String fileName)
The static initialization method Also redirects System.out, rewrites output file |
static void |
initializeErrorLogging(java.lang.String fileName,
java.lang.String initialStr)
The static initialization method which writes heading Also redirects System.out, rewrites output file |
static void |
initializeErrorLogging(java.lang.String fileName,
java.lang.String initialStr,
boolean logStdOut)
The static initialization method which writes heading Rewrites output file |
static void |
initializeErrorLogging(java.lang.String fileName,
java.lang.String initialStr,
boolean logStdOut,
boolean append)
The static initialization method |
static void |
initializeErrorLogging(java.lang.String fileName,
java.lang.String initialStr,
boolean logStdOut,
int maxSizeInKbytes)
The static initialization method to roll logfile. |
static boolean |
isLoggingInitialized()
Has the logging already been initialized? |
static boolean |
isSystemOutRedirected()
Is the System.Out being redirected to this logfile |
static void |
main(java.lang.String[] args)
A test main() |
Methods inherited from class java.io.PrintStream |
---|
append, append, append, checkError, close, flush, format, format, print, print, print, print, print, print, print, print, print, printf, printf, println, println, println, println, println, println, println, println, println, println, setError, write, write |
Methods inherited from class java.io.FilterOutputStream |
---|
write |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Method Detail |
---|
public static java.io.PrintStream getLogStream()
java.lang.RuntimeException
- if initializeErrorLogging() has not been called
yetpublic static boolean isLoggingInitialized()
public static boolean isSystemOutRedirected()
java.lang.RuntimeException
- if initializeErrorLogging() has not been called
yetpublic static java.lang.String getLogFileName()
java.lang.RuntimeException
- if initializeErrorLogging() has not been called
yetpublic static void initializeErrorLogging(java.lang.String fileName)
fileName
- the name of the log file
java.lang.RuntimeException
- if initializeErrorLogging() has already
been called yetpublic static void initializeErrorLogging(java.lang.String fileName, java.lang.String initialStr)
fileName
- the name of the log fileinitialStr
- the heading string to write to the log file when opened
java.lang.RuntimeException
- if initializeErrorLogging() has already
been calledpublic static void initializeErrorLogging(java.lang.String fileName, java.lang.String initialStr, boolean logStdOut)
fileName
- the name of the log fileinitialStr
- the heading string to write to the log file when openedlogStdOut
- true if System.Out to redirected to log file also
java.lang.RuntimeException
- if initializeErrorLogging() has already
been calledpublic static void initializeErrorLogging(java.lang.String fileName, java.lang.String initialStr, boolean logStdOut, boolean append)
fileName
- the name of the log fileinitialStr
- the heading string to write to the log file when openedlogStdOut
- true if System.Out to redirected to log file alsoappend
- true if to append to existing log, false to rewrite new
log.
java.lang.RuntimeException
- if initializeErrorLogging() has already
been called or cannot create log file dir or open log filepublic static void initializeErrorLogging(java.lang.String fileName, java.lang.String initialStr, boolean logStdOut, int maxSizeInKbytes)
fileName
- the name of the log fileinitialStr
- the heading string to write to the log file when openedlogStdOut
- true if System.Out to redirected to log file alsomaxSizeInKbytes
- roll current file to .old if it exceeds this size on
startup. Any existing .old log file is deleted.
java.lang.RuntimeException
- if initializeErrorLogging() has already
been called or cannot create log file dir or open log filepublic static void main(java.lang.String[] args)
args
- Description of Parameter
|
Forward Computing and Control Pty. Ltd. Logging Package V1.3.0 2004/11/22 |
|||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |