|
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.Objectau.com.forward.logging.Logging
public class Logging
This class provides logging initialization and debugging.
Typical use for logging is
import au.com.forward.logging.*;
static {
// set up logging also redirects System.err and System.out
// throws a LoggingException if problem with setting up Java logging
// put all log files in user's home dir
// roll log to .old when it exceed 100K
String userHome = System.getProperty("user.home",".")
+System.getProperty("file.separator","/");
Logging.initializeLogging(userHome+"StatusApplication.log",
"Log File for StatusApplication " + new Date(),true, 100);
// redirect System.out as well as System.err and append to existing log
}
If you want your application to continue even if there is an error setting
up Java Logging then use the following code
but usually you would want the application to stop if logging fails.
Note: The System.err and System.out redirection are called before
initializing Java Logging so they are still in effect even if logging fails.
static {
// set up logging also redirects System.err and System.out
// throws a LoggingException if problem with setting up Java logging
// put all log files in user's home dir
// roll log to .old when it exceed 100K
String userHome = System.getProperty("user.home",".")
+System.getProperty("file.separator","/");
try {
Logging.initializeLogging(userHome+"StatusApplication.log",
"Log File for StatusApplication " + new Date(),true, 100);
// redirect System.out as well as System.err and append to existing log
} catch (LoggingException lex) {
System.err.println(RobustFormatter.toString(lex));
}
}
If you are using Log4J or some other non-Java logging package,
then you should use
LogStdStreams.initializeErrorLogging(String, String ,boolean, int)
instead to capture the console output from the logger (and any erronous System.out.println's)
System.out.println(Logging.currentConfiguration()
);
which will dump the current logging setting in your log file.
############################################################
# Logging Configuration File
#
# To use this file specify its filename
# with the java.util.logging.config.file system property.
#
# For example:
# java -Djava.util.logging.config.file=logging.properties au.com.forward.ExampleLoggingApplication
#
############################################################
############################################################
# Global properties
############################################################
# "handlers" specifies a comma separated list of log Handler
# classes. These handlers will be installed during VM startup.
# Note that these classes must be on the system classpath.
# Add a FileHandler
handlers=java.util.logging.FileHandler
# Default global logging level.
# This specifies which kinds of events are logged across
# all loggers. For any given facility this global level
# can be overridden by a facility specific level
.level = SEVERE
############################################################
# Handler specific properties.
# Describes specific configuration info for Handlers.
############################################################
# default file output is in user's home directory.
java.util.logging.FileHandler.pattern = %h/applicationLog%u.xml
java.util.logging.FileHandler.formatter = au.com.forward.logging.LoggingXMLFormatter
############################################################
# Facility specific properties.
# Provides extra control for each logger.
############################################################
# messages:
au.com.forward.ExampleLoggingApplication.level = FINEST
Field Summary | |
---|---|
static java.lang.String |
VERSION
The version number 1.3 |
static java.lang.String |
VERSION_DATE
The version date 23nd Nov. 2004 |
Method Summary | |
---|---|
static java.lang.String |
currentConfiguration()
Returns the current logging configuration for debugging. |
static void |
initializeLogging()
Sets up the default ConsoleHandler without opening a log file |
static void |
initializeLogging(java.lang.String logFileName,
java.lang.String initialStr,
boolean logStdOut,
boolean append)
Initializes the Log file and sets up the default Console Handler |
static void |
initializeLogging(java.lang.String logFileName,
java.lang.String initialStr,
boolean logStdOut,
int maxSizeInKbytes)
Initializes a rolling Log file and sets up the default Console Handler |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final java.lang.String VERSION
public static final java.lang.String VERSION_DATE
Method Detail |
---|
public static void initializeLogging(java.lang.String logFileName, java.lang.String initialStr, boolean logStdOut, boolean append) throws LoggingException
logFileName
- 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.
LoggingException
- thrown initializeErrorLogging() has already
been called.public static void initializeLogging(java.lang.String logFileName, java.lang.String initialStr, boolean logStdOut, int maxSizeInKbytes) throws LoggingException
logFileName
- 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.
LoggingException
- thrown initializeErrorLogging() has already
been called.public static void initializeLogging() throws LoggingException
LoggingException
- thrown initializeErrorLogging() has already
been called.public static java.lang.String currentConfiguration()
Loggers created in classes are not visable in the current configuration until their class
is loaded. This means the best place to call
System.out.println(Logging.currentConfiguration());
is at the end of the application main() or in the exit code after all the classes have
been loaded.
|
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 |