public class Debug extends Object
Allows a uniform interface to file debug and exception information in a
uniform format. Debug
supports different levels/states of
filing debug information (in the ascending order): OFF
,
ERROR
, WARNING
, MESSAGE
and
ON
. A given debug level/state is enabled if the debug
state/level is set to at least that state/level. For example, if the debug
state is ERROR
, only errors will be filed. If the debug state is
WARNING
, only errors and warnings will be filed. If the debug
state is MESSAGE
, everything will be filed.
MESSAGE
and ON
are of the same levels;
the difference between them being MESSAGE
writes to a file,
whereas ON
writes to System.out.
Debug service uses the property file, DebugConfig.properties
, to
set the default debug level and the output directory where the debug files
will be placed. The properties file is located (using
ResourceBundle
semantics) from one of the directories
in the CLASSPATH.
The following keys are used to configure the Debug service. Possible values for the key 'level' are: off | error | warning | message The key 'directory' specifies the output directory where the debug files will be created.
If there is an error reading or loading the properties, debug service will redirect all debug information tocom.iplanet.services.debug.level com.iplanet.services.debug.directory
System.out
If these properties are changed, the server must be restarted for the
changes to take effect.
NOTE: Debugging is an IO intensive operation and may hurt
application performance when abused. Particularly, note that Java evaluates
the arguments to message()
and warning()
even
when debugging is turned off.
It is recommended that the debug state be checked before invoking any
message()
or warning()
methods to avoid unnecessary
argument evaluation and to maximize application performance.
Modifier and Type | Field and Description |
---|---|
static int |
ERROR
flags the state where error debugging is enabled.
|
static int |
MESSAGE
This state enables debugging of messages, warnings and errors.
|
static int |
OFF
flags the disabled debug state.
|
static int |
ON
flags the enabled debug state for warnings, errors and messages.
|
static int |
WARNING
flags the state where warning debugging is enabled, but message
debugging is disabled.
|
Modifier and Type | Method and Description |
---|---|
boolean |
debugEnabled()
Deprecated.
Use
messageEnabled() |
void |
destroy()
Destroys the debug object, closes the debug file and releases any system
resources.
|
void |
error(String msg)
Prints error messages only when debug level is greater than DEBUG.OFF.
|
void |
error(String msg,
Throwable t)
Prints error messages only if debug state is greater than
Debug.OFF.
|
protected void |
finalize()
Flushes and then closes the debug file.
|
static Debug |
getInstance(String debugName)
Returns an existing instance of Debug for the specified debug file or a
new one if no such instance already exists.
|
int |
getState()
Returns one of the five possible values:
Debug.OFF
Debug.ERROR
Debug.WARNING
Debug.MESSAGE
|
void |
message(String msg)
Prints messages only when the debug state is either
DEBUG.MESSAGE or Debug.ON.
|
void |
message(String msg,
Throwable t)
Prints debug and exception messages only when the debug
state is either DEBUG.MESSAGE or Debug.ON.
|
boolean |
messageEnabled()
Checks if message debugging is enabled.
|
void |
setDebug()
Deprecated.
Use
getInstance(java.lang.String) . getInstance(java.lang.String) will
automatically set the debug level based on the information in
DebugConfig.properties file. |
void |
setDebug(int debugType)
Sets the debug capabilities based on the values of the
debugType argument. |
void |
setDebug(String debugType)
Sets the debug capabilities based on the values of the
debugType argument. |
void |
warning(String msg)
Prints warning messages only when debug level is greater than
DEBUG.ERROR.
|
void |
warning(String msg,
Throwable t)
Prints warning messages only when debug level is greater than
DEBUG.ERROR.
|
boolean |
warningEnabled()
Checks if warning debugging is enabled.
|
public static final int OFF
public static final int ERROR
ERROR
, error debugging is also disabled.public static final int WARNING
WARNING
, warning debugging is also disabled.public static final int MESSAGE
public static final int ON
public Debug(String debugName)
getInstance(java.lang.String)
message()
, warning()
or error()
is invoked and the debug state is neither OFF
nor
ON
.
NOTE:The recommended and preferred method to create Debug
objects is getInstance(String)
. This constructor may be
deprecated in future.
debugName
- name of the debug file to create or usepublic static Debug getInstance(String debugName)
DebugConfig.properties
file. The level can be changed later
by using setDebug(int)
or setDebug(String)
debugName
- name of debug instance.Debug
.public boolean debugEnabled()
messageEnabled()
NOTE: It is recommended that messageEnabled()
be used instead of debugEnabled()
as the former is more
intuitive.>
true
if message debugging is enabled
false
if message debugging is disabledpublic boolean messageEnabled()
NOTE: Debugging is an IO intensive operation and may hurt
application performance when abused. Particularly, note that Java
evaluates arguments to message()
even when
debugging is turned off. It is recommended that
messageEnabled()
be called to check the debug state
before invoking any message()
methods to avoid
unnecessary argument evaluation and maximize application performance.
true
if message debugging is enabled
false
if message debugging is disabledpublic boolean warningEnabled()
NOTE: Debugging is an IO intensive operation and may hurt
application performance when abused. Particularly, note that Java
evaluates arguments to warning()
even when
warning debugging is turned off. It is recommended that
warningEnabled()
be called to check the debug state
before invoking any warning()
methods to avoid
unnecessary argument evaluation and maximize application performance.
true
if warning debugging is enabled
false
if warning debugging is disabledpublic int getState()
Debug.OFF
Debug.ERROR
Debug.WARNING
Debug.MESSAGE
public void message(String msg)
NOTE: Debugging is an IO intensive operation and may hurt
application performance when abused. Particularly, note that Java
evaluates arguments to message()
even when
debugging is turned off. So when the argument to this method involves
the String concatenation operator '+' or any other method invocation,
messageEnabled
MUST be used. It is recommended that
the debug state be checked by invoking messageEnabled()
before invoking any message()
methods to avoid
unnecessary argument evaluation and maximize application performance.
msg
- message to be printed. A newline will be appended to the
message before printing either to System.out
or to the debug file. If msg
is null, it is
ignored.message(String msg, Throwable t)
public void message(String msg, Throwable t)
Prints debug and exception messages only when the debug
state is either DEBUG.MESSAGE or Debug.ON. If the debug file is not
accessible and debugging is enabled, the message along with a time stamp
and thread info will be printed on System.out
.
This method creates the debug file if does not exist; otherwise it starts appending to the existing debug file. When invoked for the first time on this object, the method writes a line delimiter of '*'s.
Note that the debug file will remain open until destroy()
is invoked. To conserve file resources, you should invoke
destroy()
explicitly rather than wait for the garbage
collector to clean up.
NOTE: Debugging is an IO intensive operation and may hurt
application performance when abused. Particularly, note that
Java evaluates arguments to message()
even when
debugging is turned off. It is recommended that the debug state be
checked by invoking messageEnabled()
before invoking any
message()
methods to avoid unnecessary argument evaluation
and to maximize application performance.
msg
- message to be printed. A newline will be appended to the
message before printing either to System.out
or to the debug file. If msg
is null, it is
ignored.t
- Throwable
, on which printStackTrace
will be invoked to print the stack trace. If t
is
null, it is ignored.error(String msg, Throwable t)
public void warning(String msg)
NOTE: Debugging is an IO intensive operation and may hurt
application performance when abused. Particularly, note that
Java evaluates arguments to warning()
even when
debugging is turned off. So when the argument to this method involves
the String concatenation operator '+' or any other method invocation,
warningEnabled
MUST be used. It is recommended that
the debug state be checked by invoking warningEnabled()
before invoking any warning()
methods to avoid
unnecessary argument evaluation and to maximize application
performance.
msg
- message to be printed. A newline will be appended to the
message before printing either to System.out
or to the debug file. If msg
is null, it is
ignored.warning(String msg, Throwable t)
public void warning(String msg, Throwable t)
NOTE: Debugging is an IO intensive operation and may hurt
application performance when abused. Particularly, note that
Java evaluates arguments to warning()
even when
debugging is turned off. It is recommended that the debug state be
checked by invoking warningEnabled()
before invoking any
warning()
methods to avoid unnecessary argument evaluation
and to maximize application performance.
If the debug file is not accessible and debugging is enabled, the
message along with a time stamp and thread info will be printed on
System.out
.
This method creates the debug file if does not exist; otherwise it starts appending to the existing debug file. When invoked for the first time on this object, the method writes a line delimiter of '*'s.
Note that the debug file will remain open until destroy()
is invoked. To conserve file resources, you should invoke
destroy()
explicitly rather than wait for the garbage
collector to clean up.
msg
- message to be printed. A newline will be appended to the
message before printing either to System.out
or to the debug file. If msg
is null, it is
ignored.t
- Throwable
, on which
printStackTrace()
will be invoked to print the
stack trace. If t
is null, it is ignored.public void error(String msg)
msg
- message to be printed. A newline will be appended to the
message before printing either to System.out
or to the debug file. If msg
is null, it is
ignored.error(String msg, Throwable t)
public void error(String msg, Throwable t)
System.out
.
This method creates the debug file if does not exist; otherwise it starts appending to the existing debug file. When invoked for the first time on this object, the method writes a line delimiter of '*'s.
Note that the debug file will remain open until destroy()
is invoked. To conserve file resources, you should invoke
destroy()
explicitly rather than wait for the garbage
collector to clean up.
msg
- message to be printed. A newline will be appended to the
message before printing either to System.out
or to the debug file. If msg
is null, it is
ignored.t
- Throwable
, on which printStackTrace()
will be invoked to print the stack trace. If t
is
null, it is ignored.public void setDebug(int debugType)
debugType
argument.debugType
- is any one of five possible values:
Debug.OFF
Debug.ERROR
Debug.WARNING
Debug.MESSAGE
Debug.ON
public void setDebug()
getInstance(java.lang.String)
. getInstance(java.lang.String)
will
automatically set the debug level based on the information in
DebugConfig.properties
file.com.iplanet.services.debug.level
, in the
DebugConfig.properties
file.
DebugConfig.properties
file should be accessible from CLASSPATH.
If the property is not defined, debug level is set to error
.
public void setDebug(String debugType)
debugType
argument.debugType
- is any one of the following possible values:
System.out
public void destroy()
destroy()
is invoked. To conserve file resources, you should
invoke destroy()
explicitly rather than wait for the garbage
collector to clean up.
If this object is accessed after destroy()
has been
invoked, the results are undefined.
Copyright © 2010–2025 Open Identity Platform Community. All rights reserved.