use of com.unboundid.util.json.JSONBuffer in project ldapsdk by pingidentity.
the class Debug method debugDisconnect.
/**
* Writes debug information to indicate that a connection has been
* terminated, if appropriate.
*
* @param l The log level that should be used for the debug information.
* @param h The address of the server to which the connection was
* established.
* @param p The port of the server to which the connection was established.
* @param c The connection object for the connection that has been closed.
* It may be {@code null} for historic reasons, but should be
* non-{@code null} in new uses.
* @param t The disconnect type.
* @param m The disconnect message, if available.
* @param e The disconnect cause, if available.
*/
public static void debugDisconnect(@NotNull final Level l, @NotNull final String h, final int p, @Nullable final LDAPConnection c, @NotNull final DisconnectType t, @Nullable final String m, @Nullable final Throwable e) {
if (debugEnabled && debugTypes.contains(DebugType.CONNECT)) {
final JSONBuffer buffer = new JSONBuffer();
addCommonHeader(buffer, l, DebugType.CONNECT);
if (c != null) {
buffer.appendNumber("connection-id", c.getConnectionID());
final String connectionName = c.getConnectionName();
if (connectionName != null) {
buffer.appendString("connection-name", connectionName);
}
final String connectionPoolName = c.getConnectionPoolName();
if (connectionPoolName != null) {
buffer.appendString("connection-pool-name", connectionPoolName);
}
buffer.appendString("disconnected-from-address", h);
buffer.appendNumber("disconnected-from-port", p);
buffer.appendString("disconnect-type", t.name());
if (m != null) {
buffer.appendString("disconnect-message", m);
}
}
if (e != null) {
addCaughtException(buffer, "disconnect-cause", e);
}
addCommonFooter(buffer);
log(l, buffer, e);
}
}
use of com.unboundid.util.json.JSONBuffer in project ldapsdk by pingidentity.
the class Debug method debugASN1Write.
/**
* Writes debug information about the provided ASN.1 element to be written,
* if appropriate.
*
* @param l The log level that should be used for the debug information.
* @param e The ASN.1 element for which debug information should be written.
*/
public static void debugASN1Write(@NotNull final Level l, @NotNull final ASN1Element e) {
if (debugEnabled && debugTypes.contains(DebugType.ASN1)) {
final JSONBuffer buffer = new JSONBuffer();
addCommonHeader(buffer, l, DebugType.ASN1);
buffer.appendString("writing-asn1-element", e.toString());
addCommonFooter(buffer);
log(l, buffer);
}
}
use of com.unboundid.util.json.JSONBuffer in project ldapsdk by pingidentity.
the class Debug method 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 the {@code SEVERE} level.
*
* @param t The {@code Throwable} object that was created and will be thrown
* as a result of the coding error.
*/
public static void debugCodingError(@NotNull final Throwable t) {
if (debugEnabled && debugTypes.contains(DebugType.CODING_ERROR)) {
final JSONBuffer buffer = new JSONBuffer();
addCommonHeader(buffer, Level.SEVERE, DebugType.CODING_ERROR);
addCaughtException(buffer, "coding-error", t);
addCommonFooter(buffer);
log(Level.SEVERE, buffer, t);
}
}
use of com.unboundid.util.json.JSONBuffer in project ldapsdk by pingidentity.
the class Debug method debug.
/**
* Writes a generic debug message, if appropriate.
*
* @param l The log level that should be used for the debug information.
* @param t The debug type to use to determine whether to write the message.
* @param m The message to be written.
*/
public static void debug(@NotNull final Level l, @NotNull final DebugType t, @Nullable final String m) {
if (debugEnabled && debugTypes.contains(t)) {
final JSONBuffer buffer = new JSONBuffer();
addCommonHeader(buffer, l, t);
if (m != null) {
buffer.appendString("message", m);
}
addCommonFooter(buffer);
log(l, buffer);
}
}
use of com.unboundid.util.json.JSONBuffer in project ldapsdk by pingidentity.
the class Debug method debugASN1Read.
/**
* Writes debug information about the provided ASN.1 element that was read, if
* appropriate.
*
* @param l The log level that should be used for the debug
* information.
* @param dataType A string representation of the data type for the data
* that was read.
* @param berType The BER type for the element that was read.
* @param length The number of bytes in the value of the element that was
* read.
* @param 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 be {@code null} for an ASN.1 null element.
*/
public static void debugASN1Read(@NotNull final Level l, @NotNull final String dataType, final int berType, final int length, @Nullable final Object value) {
if (debugEnabled && debugTypes.contains(DebugType.ASN1)) {
final JSONBuffer buffer = new JSONBuffer();
addCommonHeader(buffer, l, DebugType.ASN1);
buffer.beginObject("read-asn1-element");
buffer.appendString("data-type", dataType);
buffer.appendString("ber-type", StaticUtils.toHex((byte) (berType & 0xFF)));
buffer.appendNumber("value-length", length);
if (value != null) {
if (value instanceof byte[]) {
buffer.appendString("value-bytes", StaticUtils.toHex((byte[]) value));
} else {
buffer.appendString("value-string", value.toString());
}
}
buffer.endObject();
addCommonFooter(buffer);
log(l, buffer);
}
}
Aggregations