public class LoggingUtilities
extends java.lang.Object
These utilities make use of a system property, LOGGING_PROPERTY
(HiRISE.HiPlan.Logging, to govern their behavior. The property is
treated as a boolean, so it should have the value "true" or the value
"false" - any other value, including no value, is treated as "false."
Loggers generated by these utilities (the makeLogger()
method in
particular) have a shared ConsoleHandler
attached with a logging
level of Level.INFO
. If the logging system property is "true," they
also have a shared FileHandler
attached with a logging level of
Level.ALL
. The logger's logging level is Level.ALL
if the
logging property is "true," and it is Level.INFO
if it is "false."
The file handler manages a file in the operator's home directory called HiPlanX.log.Y, where X is a unique identifier to handle the case where multiple applications are generating HiPlan logs and where Y is a versioning number. The log manager cycles through log versions automatically, retaining up to five at a time, with 0 being the most recent and 4 being the oldest. It automatically cuts the log and cycles to the next one when the log exceeds 125,000 bytes.
See LoggingUtilities.LogFormatter
for the log record format.
The enableLogging()
method sets the system property to "true"
regardless of its current value. It sets the logging level to Level.ALL
for all loggers whose names start with HIPLAN_LOGGERS
(HiRISE.HiPlan). If the shared file manager exists, it is attached
to these loggers as well; if it does not and cannot exist, the shared
console logger's level is raised to Level.ALL
(and a warning message
is printed to the standard error stream).
The disableLogging()
method sets the system property to "false"
regardless of its current value. It sets the logging level to Level.INFO
for all loggers whose names start with HIPLAN_LOGGERS
.
If the shared file handler exists, it is removed from these loggers, it is
closed, and then it is prepped for being re-created later. (Re-creating it
later will force the existing logs to cycle.) If the shared file handler
does not exist, the shared console handler's level is set to Level.INFO
.
Modifier and Type | Class and Description |
---|---|
static class |
LoggingUtilities.LogFormatter
A formatter for HiPlan logs.
|
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
DEFAULT_LOG_BASE_NAME
The default base name for the HiPlan log files.
|
static java.lang.String |
HIPLAN_LOGGERS
The prefix used for identifying loggers to be managed by these utilities.
|
static java.lang.String |
ID
Class identification name with source code version and date.
|
static int |
LOG_REVISION_COUNT
The maximum number of log files to cycle through.
|
static int |
LOG_SIZE_MAX
The maximum size of a log file.
|
static java.lang.String |
LOGGING_PROPERTY
The system property used by these utilities to manage logging.
|
Modifier and Type | Method and Description |
---|---|
static void |
connectDatabase(PIRL.Database.Database database,
java.util.logging.Logger logger) |
static void |
disableLogging()
Disables logging on all existing loggers managed by these utilities.
|
static void |
disconnectDatabase(PIRL.Database.Database database,
java.util.logging.Logger logger) |
static void |
enableLogging()
Enables logging on all existing loggers managed by these utilities.
|
static boolean |
isLoggingEnabled()
Checks whether logging is enabled.
|
static java.util.logging.Logger |
makeLogger()
Creates a new logger to be managed by these utilities.
|
public static final java.lang.String ID
public static final java.lang.String LOGGING_PROPERTY
Boolean.getBoolean(String)
.public static final java.lang.String HIPLAN_LOGGERS
public static final int LOG_REVISION_COUNT
public static final int LOG_SIZE_MAX
public static final java.lang.String DEFAULT_LOG_BASE_NAME
Constants.WRAPPER_NAME_PROPERTY
, which is set by the HiPlan application
wrappers. If the property isn't set, however, this default value is used.public static java.util.logging.Logger makeLogger()
ConsoleHandler
with a level set to Level.INFO
. If logging is enabled (as determined by the LOGGING_PROPERTY
), a shared FileHandler
is also attached, with a
level of Level.ALL
.
If logging is enabled, the logger's level is set to Level.ALL
; if
not, it is set to Level.INFO
.
The logger's name is that of the class that created it. Note that if the
fully qualified class name does not start with HIPLAN_LOGGERS
(HiRISE.HiPlan), the logger created here will not be properly
managed. This is potentially a pretty big flaw.
public static void enableLogging()
LOGGING_PROPERTY
to "true." It sets the logging
level to Level.ALL
for all managed loggers. It assigns the shared
FileHandler
to the loggers; if the handler had previously been
closed, it is created anew, triggering a log file rotation if needed. If the
handler does not exist and cannot be created, the shared ConsoleHandler
's level is set to Level.ALL
.public static void disableLogging()
LOGGING_PROPERTY
to "false." It sets the logging
level to Level.INFO
for all managed loggers and removes the shared
FileHandler
. The handler is also closed; later invocations of enableLogging()
will start a new handler, possibly trigger logging
rotation. If there is no shared file handler, the shared ConsoleHandler
's level is set to Level.INFO
.public static boolean isLoggingEnabled()
LOGGING_PROPERTY
system
property is checked. This check only has meaning for these utilities.public static void connectDatabase(PIRL.Database.Database database, java.util.logging.Logger logger) throws PIRL.Configuration.Configuration_Exception, PIRL.Database.Database_Exception
PIRL.Configuration.Configuration_Exception
PIRL.Database.Database_Exception
public static void disconnectDatabase(PIRL.Database.Database database, java.util.logging.Logger logger) throws PIRL.Database.Database_Exception
PIRL.Database.Database_Exception
Copyright \ (C) Arizona Board of Regents on behalf of the \ Planetary Image Research Laboratory, Lunar and \ Planetary Laboratory at the University of Arizona