KmsLogging

object KmsLogging

Logging utilities and conventions for KMS operations.

This object provides standardized logging patterns to ensure consistency across all KMS plugins.

Logging Levels:

  • DEBUG: Detailed diagnostic information (key lookups, cache hits, etc.)

  • INFO: Important operational events (key generation, deletion, successful operations)

  • WARN: Warning conditions (validation failures, algorithm incompatibilities)

  • ERROR: Error conditions (API failures, unexpected exceptions)

Logging Format: Use SLF4J parameterized logging for better performance and structured logging:

logger.info("Operation completed: keyId={}, algorithm={}", keyId.value, algorithm.name)
logger.error("Operation failed: keyId={}, errorCode={}", keyId.value, errorCode, exception)

Context Information: Always include relevant context in logs:

  • keyId: The key identifier

  • algorithm: The algorithm being used

  • operation: The operation being performed

  • errorCode/statusCode: HTTP or API error codes when available

  • requestId/correlationId: Request tracking IDs when available

Functions

Link copied to clipboard
fun logError(logger: Logger, message: String, keyId: String? = null, algorithm: String? = null, errorCode: String? = null, statusCode: Int? = null, requestId: String? = null, exception: Throwable? = null)

Logs an error condition with full context.

Link copied to clipboard
fun logKeyDeleted(logger: Logger, keyId: String, additionalContext: Map<String, Any?> = emptyMap())

Logs a key deletion operation.

Link copied to clipboard
fun logKeyGenerated(logger: Logger, keyId: String, algorithm: String, additionalContext: Map<String, Any?> = emptyMap())

Logs a successful key generation operation.

Link copied to clipboard
fun logKeyNotFound(logger: Logger, keyId: String, operation: String, additionalContext: Map<String, Any?> = emptyMap())

Logs a key not found condition (debug level, as this is often expected).

Link copied to clipboard
fun logSigningSuccess(logger: Logger, keyId: String, algorithm: String, dataSize: Int, signatureSize: Int)

Logs a successful signing operation.

Link copied to clipboard
fun logWarning(logger: Logger, message: String, keyId: String? = null, algorithm: String? = null, reason: String? = null)

Logs a warning condition (validation failures, incompatibilities, etc.).