Class Debug
- java.lang.Object
-
- com.sun.identity.saml2.idpdiscovery.Debug
-
public class Debug extends Object
Allows a uniform interface to file debug and exception information in a uniform format.
Debugsupports different levels/states of filing debug information (in the ascending order):OFF,ERROR,WARNING,MESSAGEandON. 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 isERROR, only errors will be filed. If the debug state isWARNING, only errors and warnings will be filed. If the debug state isMESSAGE, everything will be filed.MESSAGEandONare of the same levels; the difference between them beingMESSAGEwrites to a file, whereasONwrites 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 (usingResourceBundlesemantics) 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.outIf 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()andwarning()even when debugging is turned off. It is recommended that the debug state be checked before invoking anymessage()orwarning()methods to avoid unnecessary argument evaluation and to maximize application performance.
-
-
Field Summary
Fields Modifier and Type Field Description static intERRORflags the state where error debugging is enabled.static intMESSAGEThis state enables debugging of messages, warnings and errors.static intOFFflags the disabled debug state.static intONflags the enabled debug state for warnings, errors and messages.static intWARNINGflags the state where warning debugging is enabled, but message debugging is disabled.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description booleandebugEnabled()Deprecated.UsemessageEnabled()voiddestroy()Destroys the debug object, closes the debug file and releases any system resources.voiderror(String msg)Prints error messages only when debug level is greater than DEBUG.OFF.voiderror(String msg, Throwable t)Prints error messages only if debug state is greater than Debug.OFF.protected voidfinalize()Flushes and then closes the debug file.static DebuggetInstance(String debugName)Returns an existing instance of Debug for the specified debug file or a new one if no such instance already exists.intgetState()Returns one of the five possible values:Debug.OFFDebug.ERRORDebug.WARNINGDebug.MESSAGEDebug.ON voidmessage(String msg)Prints messages only when the debug state is either DEBUG.MESSAGE or Debug.ON.voidmessage(String msg, Throwable t)Prints debug and exception messages only when the debug state is either DEBUG.MESSAGE or Debug.ON.booleanmessageEnabled()Checks if message debugging is enabled.voidsetDebug()Deprecated.voidsetDebug(int debugType)Sets the debug capabilities based on the values of thedebugTypeargument.voidsetDebug(String debugType)Sets the debug capabilities based on the values of thedebugTypeargument.voidwarning(String msg)Prints warning messages only when debug level is greater than DEBUG.ERROR.voidwarning(String msg, Throwable t)Prints warning messages only when debug level is greater than DEBUG.ERROR.booleanwarningEnabled()Checks if warning debugging is enabled.
-
-
-
Field Detail
-
OFF
public static final int OFF
flags the disabled debug state.- See Also:
- Constant Field Values
-
ERROR
public static final int ERROR
flags the state where error debugging is enabled. When debugging is set to less thanERROR, error debugging is also disabled.- See Also:
- Constant Field Values
-
WARNING
public static final int WARNING
flags the state where warning debugging is enabled, but message debugging is disabled. When debugging is set to less thanWARNING, warning debugging is also disabled.- See Also:
- Constant Field Values
-
MESSAGE
public static final int MESSAGE
This state enables debugging of messages, warnings and errors.- See Also:
- Constant Field Values
-
ON
public static final int ON
flags the enabled debug state for warnings, errors and messages. Printing to a file is disabled. All printing is done on System.out.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
Debug
public Debug(String debugName)
Deprecated.This constructor takes as an argument the name of the debug file. The debug file is neither created nor opened until the first timemessage(),warning()orerror()is invoked and the debug state is neitherOFFnorON.NOTE:The recommended and preferred method to create Debug objects is
getInstance(String). This constructor may be deprecated in future.- Parameters:
debugName- name of the debug file to create or use
-
-
Method Detail
-
getInstance
public 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. If a Debug object has to be created, its level is set to the level defined in theDebugConfig.propertiesfile. The level can be changed later by usingsetDebug(int)orsetDebug(String)- Parameters:
debugName- name of debug instance.- Returns:
- an instance of
Debug.
-
debugEnabled
public boolean debugEnabled()
Deprecated.UsemessageEnabled()Checks if message debugging is enabled.NOTE: It is recommended that
messageEnabled()be used instead ofdebugEnabled()as the former is more intuitive.>- Returns:
trueif message debugging is enabledfalseif message debugging is disabled
-
messageEnabled
public boolean messageEnabled()
Checks if message debugging is enabled.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 thatmessageEnabled()be called to check the debug state before invoking anymessage()methods to avoid unnecessary argument evaluation and maximize application performance.- Returns:
trueif message debugging is enabledfalseif message debugging is disabled
-
warningEnabled
public boolean warningEnabled()
Checks if warning debugging is enabled.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 thatwarningEnabled()be called to check the debug state before invoking anywarning()methods to avoid unnecessary argument evaluation and maximize application performance.- Returns:
trueif warning debugging is enabledfalseif warning debugging is disabled
-
getState
public int getState()
Returns one of the five possible values:Debug.OFFDebug.ERRORDebug.WARNINGDebug.MESSAGEDebug.ON
- Returns:
- debug state.
-
message
public void message(String msg)
Prints messages only when the debug state is either DEBUG.MESSAGE or Debug.ON.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,messageEnabledMUST be used. It is recommended that the debug state be checked by invokingmessageEnabled()before invoking anymessage()methods to avoid unnecessary argument evaluation and maximize application performance.- Parameters:
msg- message to be printed. A newline will be appended to the message before printing either toSystem.outor to the debug file. Ifmsgis null, it is ignored.- See Also:
message(String msg, Throwable t)
-
message
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 invokedestroy()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 invokingmessageEnabled()before invoking anymessage()methods to avoid unnecessary argument evaluation and to maximize application performance.- Parameters:
msg- message to be printed. A newline will be appended to the message before printing either toSystem.outor to the debug file. Ifmsgis null, it is ignored.t-Throwable, on whichprintStackTracewill be invoked to print the stack trace. Iftis null, it is ignored.- See Also:
error(String msg, Throwable t)
-
warning
public void warning(String msg)
Prints warning messages only when debug level is greater than DEBUG.ERROR.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,warningEnabledMUST be used. It is recommended that the debug state be checked by invokingwarningEnabled()before invoking anywarning()methods to avoid unnecessary argument evaluation and to maximize application performance.- Parameters:
msg- message to be printed. A newline will be appended to the message before printing either toSystem.outor to the debug file. Ifmsgis null, it is ignored.- See Also:
warning(String msg, Throwable t)
-
warning
public void warning(String msg, Throwable t)
Prints warning messages only when debug level is greater than DEBUG.ERROR.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 invokingwarningEnabled()before invoking anywarning()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 invokedestroy()explicitly rather than wait for the garbage collector to clean up.- Parameters:
msg- message to be printed. A newline will be appended to the message before printing either toSystem.outor to the debug file. Ifmsgis null, it is ignored.t-Throwable, on whichprintStackTrace()will be invoked to print the stack trace. Iftis null, it is ignored.
-
error
public void error(String msg)
Prints error messages only when debug level is greater than DEBUG.OFF.- Parameters:
msg- message to be printed. A newline will be appended to the message before printing either toSystem.outor to the debug file. Ifmsgis null, it is ignored.- See Also:
error(String msg, Throwable t)
-
error
public void error(String msg, Throwable t)
Prints error messages only if debug state is greater than Debug.OFF. If the debug file is not accessible and debugging is enabled, the message along with a time stamp and thread info will be printed onSystem.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 invokedestroy()explicitly rather than wait for the garbage collector to clean up.- Parameters:
msg- message to be printed. A newline will be appended to the message before printing either toSystem.outor to the debug file. Ifmsgis null, it is ignored.t-Throwable, on whichprintStackTrace()will be invoked to print the stack trace. Iftis null, it is ignored.
-
setDebug
public void setDebug(int debugType)
Sets the debug capabilities based on the values of thedebugTypeargument.- Parameters:
debugType- is any one of five possible values:Debug.OFFDebug.ERRORDebug.WARNINGDebug.MESSAGEDebug.ON
-
setDebug
public void setDebug()
Deprecated.UsegetInstance(java.lang.String).getInstance(java.lang.String)will automatically set the debug level based on the information inDebugConfig.propertiesfile.Enables or disables debugging based on the value of debug attribute,com.iplanet.services.debug.level, in theDebugConfig.propertiesfile.DebugConfig.propertiesfile should be accessible from CLASSPATH. If the property is not defined, debug level is set toerror.
-
setDebug
public void setDebug(String debugType)
Sets the debug capabilities based on the values of thedebugTypeargument.- Parameters:
debugType- is any one of the following possible values:- off - debugging is disabled
- on - all debugging is enabled and written to
System.out - message - message debugging is enabled and written to the debug file
- warning - warning debugging is enabled and written to the debug file
- error - error debugging is enabled and written to the debug file
-
destroy
public void destroy()
Destroys the debug object, closes the debug file and releases any system resources. Note that the debug file will remain open untildestroy()is invoked. To conserve file resources, you should invokedestroy()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.
-
-