When developing a library, you should use info level or less severe (info, debug, trace) to avoid overwhelming the host application's logging system.
trace: Use for detailed diagnostic information and internal state needed to diagnose hard-to-reproduce bugs. Assume this will not be used in production.debug: Use for high-level operational overviews, such as connection events or major decisions. This may be enabled in some production environments.info: Use sparingly for issues that cannot be communicated through other means (e.g., recoverable failures like connection retries). Do not use info for normal successful operations.
Warning/Error levels: Libraries should generally not log at warning or more severe levels unless it is a one-time event (e.g., during startup) that cannot flood the logs.
// ✅ Good: Trace level for detailed diagnostics
logger.trace("Connection pool state", metadata: [
"active": "\(activeConnections)",
"idle": "\(idleConnections)",
"pending": "\(pendingRequests)"
])
// ✅ Good: Debug level for high-value operational info
logger.debug("Database connection established", metadata: [
"host": "\(host)",
"database": "\(database)",
"connectionTime": "\(duration)"
])
// ✅ Good: Info level for issues that can't be communicated through other means
logger.info("Connection failed, retrying", metadata: [
"attempt": "\(attemptNumber)",
"maxRetries": "\(maxRetries)",
"host": "\(host)"
])