Package com.unboundid.util
Class Debug
java.lang.Object
com.unboundid.util.Debug
- All Implemented Interfaces:
Serializable
@ThreadSafety(level=COMPLETELY_THREADSAFE)
public final class Debug
extends Object
implements Serializable
This class provides a means of enabling and configuring debugging in the LDAP
SDK.
Access to debug information can be enabled through applications that use the SDK by calling the
The LDAP SDK debugging subsystem uses the Java logging framework available through the
Access to debug information can be enabled through applications that use the SDK by calling the
setEnabled(boolean) methods, or it can also be
enabled without any code changes through the use of system properties. In
particular, the PROPERTY_DEBUG_ENABLED,
PROPERTY_DEBUG_LEVEL, and PROPERTY_DEBUG_TYPE
properties may be used to control debugging without the need to alter any
code within the application that uses the SDK.
The LDAP SDK debugging subsystem uses the Java logging framework available through the
java.util.logging package with a logger name of
"com.unboundid.ldap.sdk". The getLogger() method may
be used to access the logger instance used by the LDAP SDK.
Example
The following example demonstrates the process that may be used to enable debugging within the LDAP SDK and write information about all messages with aWARNING level or higher to a specified file:
Debug.setEnabled(true); Logger logger = Debug.getLogger(); FileHandler fileHandler = new FileHandler(logFilePath); fileHandler.setLevel(Level.WARNING); logger.addHandler(fileHandler);
- See Also:
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe name that will be used for the Java logger that will actually handle the debug messages if debugging is enabled.static final StringThe name of the system property that will be used to enable debugging in the UnboundID LDAP SDK for Java.static final StringThe name of the system property that will be used to indicate that debug log messages should be written to the specified file.static final StringThe name of the system property that will be used to set the initial level for the debug logger.static final StringThe name of the system property that will be used to indicate that debugging should be enabled for specific types of messages.static final StringThe name of the system property that will be used to indicate whether the LDAP SDK should default to including information about the exception's cause in an exception message obtained from theStaticUtils.getExceptionMessage(Throwable)method.static final StringThe name of the system property that may be used to indicate whether stack trace information for the thread calling the debug method should be included in debug log messages.static final StringThe name of the system property that will be used to indicate whether the LDAP SDK should default to including a full stack trace (albeit in condensed form) in an exception message obtained from theStaticUtils.getExceptionMessage(Throwable)method.static final StringThe name of the system property that will be used ot indicate whether debug messages (which will be formatted as JSON objects) should be generated using a multi-line string representation. -
Method Summary
Modifier and TypeMethodDescriptionstatic voidWrites a generic debug message, if appropriate.static voidWrites a generic debug message, if appropriate.static voidWrites debug information about the provided ASN.1 element that was read, if appropriate.static voiddebugASN1Read(Level l, ASN1Element e) Writes debug information about the provided ASN.1 element that was read, if appropriate.static voiddebugASN1Read(Level l, String dataType, int berType, int length, Object value) Writes debug information about the provided ASN.1 element that was read, if appropriate.static voidWrites debug information about the provided ASN.1 element to be written, if appropriate.static voidWrites debug information about the provided ASN.1 element to be written, if appropriate.static voiddebugASN1Write(Level l, ASN1Buffer b) Writes debug information about the provided ASN.1 element to be written, if appropriate.static voiddebugASN1Write(Level l, ASN1Element e) Writes debug information about the provided ASN.1 element to be written, if appropriate.static voidWrites debug information about a coding error detected in the use of the LDAP SDK.static voiddebugConnect(String h, int p) Writes debug information to indicate that a connection has been established, if appropriate.static voiddebugConnect(String h, int p, LDAPConnection c) Writes debug information to indicate that a connection has been established, if appropriate.static voiddebugConnect(Level l, String h, int p) Writes debug information to indicate that a connection has been established, if appropriate.static voiddebugConnect(Level l, String h, int p, LDAPConnection c) Writes debug information to indicate that a connection has been established, if appropriate.static voiddebugConnectionPool(Level l, AbstractConnectionPool p, LDAPConnection c, String m, Throwable e) Writes debug information about interaction with a connection pool.static voiddebugDisconnect(String h, int p, DisconnectType t, String m, Throwable e) Writes debug information to indicate that a connection has been terminated, if appropriate.static voiddebugDisconnect(String h, int p, LDAPConnection c, DisconnectType t, String m, Throwable e) Writes debug information to indicate that a connection has been terminated, if appropriate.static voiddebugDisconnect(Level l, String h, int p, DisconnectType t, String m, Throwable e) Writes debug information to indicate that a connection has been terminated, if appropriate.static voiddebugDisconnect(Level l, String h, int p, LDAPConnection c, DisconnectType t, String m, Throwable e) Writes debug information to indicate that a connection has been terminated, if appropriate.static booleanIndicates whether any form of debugging is enabled.static booleandebugEnabled(DebugType debugType) Indicates whether debugging is enabled for messages of the specified debug type.static voidWrites debug information about the provided exception, if appropriate.static voiddebugException(Level l, Throwable t) Writes debug information about the provided exception, if appropriate.static voidWrites debug information about the provided request, if appropriate.static voiddebugLDAPRequest(LDAPRequest r, int i, LDAPConnection c) Writes debug information about the provided request, if appropriate.static voiddebugLDAPRequest(Level l, LDAPRequest r) Writes debug information about the provided request, if appropriate.static voiddebugLDAPRequest(Level l, LDAPRequest r, int i, LDAPConnection c) Writes debug information about the provided request, if appropriate.static voiddebugLDAPRequest(Level l, String s, int i, LDAPConnection c) Writes debug information about the provided request, if appropriate.static voidWrites debug information about the provided result, if appropriate.static voidWrites debug information about the provided result, if appropriate.static voiddebugLDAPResult(Level l, LDAPResponse r) Writes debug information about the provided result, if appropriate.static voiddebugLDAPResult(Level l, LDAPResponse r, LDAPConnection c) Writes debug information about the provided result, if appropriate.static voidWrites debug information about the provided record read from LDIF, if appropriate.static voiddebugLDIFRead(Level l, LDIFRecord r) Writes debug information about the provided record read from LDIF, if appropriate.static voidWrites debug information about the provided LDIF record to be written, if if appropriate.static voiddebugLDIFWrite(Level l, LDIFRecord r) Writes debug information about the provided LDIF record to be written, if appropriate.static voiddebugMonitor(Entry e, String m) Writes debug information about monitor entry parsing.static voiddebugMonitor(Level l, Entry e, String m) Writes debug information about monitor entry parsing, if appropriate.static voiddebugToFile(File file, boolean includeTimestamp, boolean includeStackTrace, String message) Appends the provided debug message to the specified file.static voiddebugToFile(File file, String message) Appends the provided debug message to the specified file.static voiddebugToFile(String path, String message) Appends the provided debug message to the specified file.Retrieves the set of debug types that will be used if debugging is enabled.static LoggerRetrieves the logger that will be used to write the debug messages.static booleanIndicates whether log messages should include a stack trace of the thread that invoked the debug method.static voidInitializes this debugger with the default settings.static voidinitialize(Properties properties) Initializes this debugger with settings from the provided set of properties.static LevelparseDebugLogLevel(String levelString) Attempts to parse the provided string as a debug log level.static voidsetEnabled(boolean enabled) Specifies whether debugging should be enabled.static voidsetEnabled(boolean enabled, Set<DebugType> types) Specifies whether debugging should be enabled.static voidsetIncludeStackTrace(boolean includeStackTrace) Specifies whether log messages should include a stack trace of the thread that invoked the debug method.static voidsetUseMultiLineDebugMessages(boolean useMultiLineDebugMessages) Specifies whether debug messages (which will be formatted as JSON objects) should use a multi-line or single-line string representation.static booleanIndicates whether debug messages (which will be formatted as JSON objects) should use a multi-line or single-line string representation.
-
Field Details
-
PROPERTY_DEBUG_ENABLED
The name of the system property that will be used to enable debugging in the UnboundID LDAP SDK for Java. The fully-qualified name for this property is "com.unboundid.ldap.sdk.debug.enabled". If it is set, then it should have a value of either "true" or "false".- See Also:
-
PROPERTY_INCLUDE_STACK_TRACE
The name of the system property that may be used to indicate whether stack trace information for the thread calling the debug method should be included in debug log messages. The fully-qualified name for this property is "com.unboundid.ldap.sdk.debug.includeStackTrace". If it is set, then it should have a value of either "true" or "false".- See Also:
-
PROPERTY_DEBUG_LEVEL
The name of the system property that will be used to set the initial level for the debug logger. The fully-qualified name for this property is "com.unboundid.ldap.sdk.debug.level". If it is set, then it should be one of the strings "SEVERE", "WARNING", "INFO", "CONFIG", "FINE", "FINER", or "FINEST".- See Also:
-
PROPERTY_DEBUG_TYPE
The name of the system property that will be used to indicate that debugging should be enabled for specific types of messages. The fully-qualified name for this property is "com.unboundid.ldap.sdk.debug.type". If it is set, then it should be a comma-delimited list of the names of the desired debug types. See theDebugTypeenum for the available debug types.- See Also:
-
PROPERTY_INCLUDE_CAUSE_IN_EXCEPTION_MESSAGES
The name of the system property that will be used to indicate whether the LDAP SDK should default to including information about the exception's cause in an exception message obtained from theStaticUtils.getExceptionMessage(Throwable)method. By default, the cause will not be included in most messages.- See Also:
-
PROPERTY_INCLUDE_STACK_TRACE_IN_EXCEPTION_MESSAGES
The name of the system property that will be used to indicate whether the LDAP SDK should default to including a full stack trace (albeit in condensed form) in an exception message obtained from theStaticUtils.getExceptionMessage(Throwable)method. By default, stack traces will not be included in most messages.- See Also:
-
PROPERTY_USE_MULTI_LINE_DEBUG_MESSAGES
The name of the system property that will be used ot indicate whether debug messages (which will be formatted as JSON objects) should be generated using a multi-line string representation. By default, debug message will use a single-line string representation.- See Also:
-
PROPERTY_DEBUG_FILE
The name of the system property that will be used to indicate that debug log messages should be written to the specified file. The fully-qualified name for this property is "com.unboundid.ldap.sdk.debug.file". If it is set, then its value should be a pattern that describes the path to the log file to create as described in the Javadoc documentation for thejava.util.logging.FileHandlerclass.- See Also:
-
LOGGER_NAME
The name that will be used for the Java logger that will actually handle the debug messages if debugging is enabled.- See Also:
-
-
Method Details
-
initialize
Initializes this debugger with the default settings. Debugging will be disabled, the set of debug types will include all types, and the debug level will be "ALL". -
initialize
Initializes this debugger with settings from the provided set of properties. Any debug setting that isn't configured in the provided properties will be initialized with its default value.- Parameters:
properties- The set of properties to use to initialize this debugger.
-
getLogger
Retrieves the logger that will be used to write the debug messages.- Returns:
- The logger that will be used to write the debug messages.
-
debugEnabled
Indicates whether any form of debugging is enabled.- Returns:
trueif debugging is enabled, orfalseif not.
-
debugEnabled
Indicates whether debugging is enabled for messages of the specified debug type.- Parameters:
debugType- The debug type for which to make the determination.- Returns:
trueif debugging is enabled for messages of the specified debug type, orfalseif not.
-
setEnabled
Specifies whether debugging should be enabled. If it should be, then it will be enabled for all debug types.- Parameters:
enabled- Specifies whether debugging should be enabled.
-
setEnabled
Specifies whether debugging should be enabled. If it should be, then it will be enabled for all debug types in the provided set.- Parameters:
enabled- Specifies whether debugging should be enabled.types- The set of debug types that should be enabled. It may benullor empty to indicate that it should be for all debug types.
-
includeStackTrace
Indicates whether log messages should include a stack trace of the thread that invoked the debug method.- Returns:
trueif log messages should include a stack trace of the thread that invoked the debug method, orfalseif not.
-
setIncludeStackTrace
Specifies whether log messages should include a stack trace of the thread that invoked the debug method.- Parameters:
includeStackTrace- Indicates whether log messages should include a stack trace of the thread that invoked the debug method.
-
useMultiLineDebugMessages
Indicates whether debug messages (which will be formatted as JSON objects) should use a multi-line or single-line string representation.- Returns:
trueif debug messages should be formatted as multi-line strings, orfalseif debug messages should be formatted as single-line strings.
-
setUseMultiLineDebugMessages
Specifies whether debug messages (which will be formatted as JSON objects) should use a multi-line or single-line string representation.- Parameters:
useMultiLineDebugMessages- Indicates whether debug messages should be formatted as multi-line strings (iftrue) or single-line strings (iffalse).
-
getDebugTypes
Retrieves the set of debug types that will be used if debugging is enabled.- Returns:
- The set of debug types that will be used if debugging is enabled.
-
debugException
Writes debug information about the provided exception, if appropriate. If it is to be logged, then it will be sent to the underlying logger using theWARNINGlevel.- Parameters:
t- The exception for which debug information should be written.
-
debugException
Writes debug information about the provided exception, if appropriate.- Parameters:
l- The log level that should be used for the debug information.t- The exception for which debug information should be written.
-
debugConnect
Writes debug information to indicate that a connection has been established, if appropriate. If it is to be logged, then it will be sent to the underlying logger using theINFOlevel.- Parameters:
h- The address of the server to which the connection was established.p- The port of the server to which the connection was established.
-
debugConnect
Writes debug information to indicate that a connection has been established, if appropriate.- Parameters:
l- The log level that should be used for the debug information.h- The address of the server to which the connection was established.p- The port of the server to which the connection was established.
-
debugConnect
Writes debug information to indicate that a connection has been established, if appropriate. If it is to be logged, then it will be sent to the underlying logger using theINFOlevel.- Parameters:
h- The address of the server to which the connection was established.p- The port of the server to which the connection was established.c- The connection object for the connection that has been established. It may benullfor historic reasons, but should be non-nullin new uses.
-
debugConnect
public static void debugConnect(@NotNull Level l, @NotNull String h, int p, @Nullable LDAPConnection c) Writes debug information to indicate that a connection has been established, if appropriate.- Parameters:
l- The log level that should be used for the debug information.h- The address of the server to which the connection was established.p- The port of the server to which the connection was established.c- The connection object for the connection that has been established. It may benullfor historic reasons, but should be non-nullin new uses.
-
debugDisconnect
public static void debugDisconnect(@NotNull String h, int p, @NotNull DisconnectType t, @Nullable String m, @Nullable Throwable e) Writes debug information to indicate that a connection has been terminated, if appropriate. If it is to be logged, then it will be sent to the underlying logger using theINFOlevel.- Parameters:
h- The address of the server to which the connection was established.p- The port of the server to which the connection was established.t- The disconnect type.m- The disconnect message, if available.e- The disconnect cause, if available.
-
debugDisconnect
public static void debugDisconnect(@NotNull Level l, @NotNull String h, int p, @NotNull DisconnectType t, @Nullable String m, @Nullable Throwable e) Writes debug information to indicate that a connection has been terminated, if appropriate.- Parameters:
l- The log level that should be used for the debug information.h- The address of the server to which the connection was established.p- The port of the server to which the connection was established.t- The disconnect type.m- The disconnect message, if available.e- The disconnect cause, if available.
-
debugDisconnect
public static void debugDisconnect(@NotNull String h, int p, @Nullable LDAPConnection c, @NotNull DisconnectType t, @Nullable String m, @Nullable Throwable e) Writes debug information to indicate that a connection has been terminated, if appropriate. If it is to be logged, then it will be sent to the underlying logger using theINFOlevel.- Parameters:
h- The address of the server to which the connection was established.p- The port of the server to which the connection was established.c- The connection object for the connection that has been closed. It may benullfor historic reasons, but should be non-nullin new uses.t- The disconnect type.m- The disconnect message, if available.e- The disconnect cause, if available.
-
debugDisconnect
public static void debugDisconnect(@NotNull Level l, @NotNull String h, int p, @Nullable LDAPConnection c, @NotNull DisconnectType t, @Nullable String m, @Nullable Throwable e) Writes debug information to indicate that a connection has been terminated, if appropriate.- Parameters:
l- The log level that should be used for the debug information.h- The address of the server to which the connection was established.p- The port of the server to which the connection was established.c- The connection object for the connection that has been closed. It may benullfor historic reasons, but should be non-nullin new uses.t- The disconnect type.m- The disconnect message, if available.e- The disconnect cause, if available.
-
debugLDAPRequest
Writes debug information about the provided request, if appropriate. If it is to be logged, then it will be sent to the underlying logger using theINFOlevel.- Parameters:
r- The LDAP request for which debug information should be written.
-
debugLDAPRequest
Writes debug information about the provided request, if appropriate.- Parameters:
l- The log level that should be used for the debug information.r- The LDAP request for which debug information should be written.
-
debugLDAPRequest
Writes debug information about the provided request, if appropriate. If it is to be logged, then it will be sent to the underlying logger using theINFOlevel.- Parameters:
r- The LDAP request for which debug information should be written.i- The message ID for the request that will be sent. It may be negative if no message ID is available.c- The connection on which the request will be sent. It may benullfor historic reasons, but should be non-nullin new uses.
-
debugLDAPRequest
public static void debugLDAPRequest(@NotNull Level l, @NotNull LDAPRequest r, int i, @Nullable LDAPConnection c) Writes debug information about the provided request, if appropriate.- Parameters:
l- The log level that should be used for the debug information.r- The LDAP request for which debug information should be written.i- The message ID for the request that will be sent. It may be negative if no message ID is available.c- The connection on which the request will be sent. It may benullfor historic reasons, but should be non-nullin new uses.
-
debugLDAPRequest
public static void debugLDAPRequest(@NotNull Level l, @NotNull String s, int i, @Nullable LDAPConnection c) Writes debug information about the provided request, if appropriate.- Parameters:
l- The log level that should be used for the debug information.s- A string representation of the LDAP request for which debug information should be written.i- The message ID for the request that will be sent. It may be negative if no message ID is available.c- The connection on which the request will be sent. It may benullfor historic reasons, but should be non-nullin new uses.
-
debugLDAPResult
Writes debug information about the provided result, if appropriate. If it is to be logged, then it will be sent to the underlying logger using theINFOlevel.- Parameters:
r- The result for which debug information should be written.
-
debugLDAPResult
Writes debug information about the provided result, if appropriate.- Parameters:
l- The log level that should be used for the debug information.r- The result for which debug information should be written.
-
debugLDAPResult
Writes debug information about the provided result, if appropriate. If it is to be logged, then it will be sent to the underlying logger using theINFOlevel.- Parameters:
r- The result for which debug information should be written.c- The connection on which the response was received. It may benullfor historic reasons, but should be non-nullin new uses.
-
debugLDAPResult
public static void debugLDAPResult(@NotNull Level l, @NotNull LDAPResponse r, @Nullable LDAPConnection c) Writes debug information about the provided result, if appropriate.- Parameters:
l- The log level that should be used for the debug information.r- The result for which debug information should be written.c- The connection on which the response was received. It may benullfor historic reasons, but should be non-nullin new uses.
-
debugASN1Write
Writes debug information about the provided ASN.1 element to be written, if appropriate. If it is to be logged, then it will be sent to the underlying logger using theINFOlevel.- Parameters:
e- The ASN.1 element for which debug information should be written.
-
debugASN1Write
Writes debug information about the provided ASN.1 element to be written, if appropriate.- Parameters:
l- The log level that should be used for the debug information.e- The ASN.1 element for which debug information should be written.
-
debugASN1Write
Writes debug information about the provided ASN.1 element to be written, if appropriate. If it is to be logged, then it will be sent to the underlying logger using theINFOlevel.- Parameters:
b- The ASN.1 buffer with the information to be written.
-
debugASN1Write
Writes debug information about the provided ASN.1 element to be written, if appropriate.- Parameters:
l- The log level that should be used for the debug information.b- The ASN1Buffer with the information to be written.
-
debugASN1Read
Writes debug information about the provided ASN.1 element that was read, if appropriate. If it is to be logged, then it will be sent to the underlying logger using theINFOlevel.- Parameters:
e- The ASN.1 element for which debug information should be written.
-
debugASN1Read
Writes debug information about the provided ASN.1 element that was read, if appropriate.- Parameters:
l- The log level that should be used for the debug information.e- The ASN.1 element for which debug information should be written.
-
debugASN1Read
public static void debugASN1Read(@NotNull Level l, @NotNull String dataType, int berType, int length, @Nullable Object value) Writes debug information about the provided ASN.1 element that was read, if appropriate.- Parameters:
l- The log level that should be used for the debug information.dataType- A string representation of the data type for the data that was read.berType- The BER type for the element that was read.length- The number of bytes in the value of the element that was read.value- A representation of the value that was read. The debug message will include the string representation of this value, unless the value is a byte array in which it will be a hex representation of the bytes that it contains. It may benullfor an ASN.1 null element.
-
debugConnectionPool
public static void debugConnectionPool(@NotNull Level l, @NotNull AbstractConnectionPool p, @Nullable LDAPConnection c, @Nullable String m, @Nullable Throwable e) Writes debug information about interaction with a connection pool.- Parameters:
l- The log level that should be used for the debug information.p- The associated connection pool.c- The associated LDAP connection, if appropriate.m- A message with information about the pool interaction.e- An exception to include with the log message, if appropriate.
-
debugLDIFWrite
Writes debug information about the provided LDIF record to be written, if if appropriate. If it is to be logged, then it will be sent to the underlying logger using theINFOlevel.- Parameters:
r- The LDIF record for which debug information should be written.
-
debugLDIFWrite
Writes debug information about the provided LDIF record to be written, if appropriate.- Parameters:
l- The log level that should be used for the debug information.r- The LDIF record for which debug information should be written.
-
debugLDIFRead
Writes debug information about the provided record read from LDIF, if appropriate. If it is to be logged, then it will be sent to the underlying logger using theINFOlevel.- Parameters:
r- The LDIF record for which debug information should be written.
-
debugLDIFRead
Writes debug information about the provided record read from LDIF, if appropriate.- Parameters:
l- The log level that should be used for the debug information.r- The LDIF record for which debug information should be written.
-
debugMonitor
Writes debug information about monitor entry parsing. If it is to be logged, then it will be sent to the underlying logger using theFINElevel.- Parameters:
e- The entry containing the monitor information being parsed.m- The message to be written to the debug logger.
-
debugMonitor
Writes debug information about monitor entry parsing, if appropriate.- Parameters:
l- The log level that should be used for the debug information.e- The entry containing the monitor information being parsed.m- The message to be written to the debug logger.
-
debugCodingError
Writes debug information about a coding error detected in the use of the LDAP SDK. If it is to be logged, then it will be sent to the underlying logger using theSEVERElevel.- Parameters:
t- TheThrowableobject that was created and will be thrown as a result of the coding error.
-
debug
Writes a generic debug message, if appropriate.- Parameters:
l- The log level that should be used for the debug information.t- The debug type to use to determine whether to write the message.m- The message to be written.
-
debug
public static void debug(@NotNull Level l, @NotNull DebugType t, @Nullable String m, @Nullable Throwable e) Writes a generic debug message, if appropriate.- Parameters:
l- The log level that should be used for the debug information.t- The debug type to use to determine whether to write the message.m- The message to be written.e- An exception to include with the log message.
-
debugToFile
Appends the provided debug message to the specified file. This method should be safe to call concurrently, even across multiple processes.- Parameters:
path- The path to the file to which the message should be appended. It must not benull.message- The debug message to be appended to the file. It must not benull.
-
debugToFile
Appends the provided debug message to the specified file. This method should be safe to call concurrently, even across multiple processes.- Parameters:
file- The file to which the message should be appended. It must not benull.message- The debug message to be appended to the file. It must not benull.
-
debugToFile
public static void debugToFile(@NotNull File file, boolean includeTimestamp, boolean includeStackTrace, @NotNull String message) Appends the provided debug message to the specified file. This method should be safe to call concurrently, even across multiple processes.- Parameters:
file- The file to which the message should be appended. It must not benull.includeTimestamp- Indicates whether to include a timestamp along with the debug message.includeStackTrace- Indicates whether to include a stack trace along with the debug message.message- The debug message to be appended to the file. It must not benull.
-
parseDebugLogLevel
@NotNull public static Level parseDebugLogLevel(@NotNull String levelString) throws IllegalArgumentException Attempts to parse the provided string as a debug log level.- Parameters:
levelString- The string representation of the level to use. It must not benullor empty.- Returns:
- The log level that was parsed.
- Throws:
IllegalArgumentException- If the provided string cannot be parsed as a valid debug log level.
-