Skip to content

Commit 03a066f

Browse files
committed
Audit log message severity levels
Motivation: Following the SSWG guidelines for libraries and log levels, because much of the library's behavior is expressed in the language and NIO framework as errors and failed ELFs, logging at error is "verbose" and takes away control from developers. Modifications: Log messages have been adjusted to more accurately represent when and how the log message should be used, especially when ELFs are failed or errors are thrown. Result: Developers won't have log messages at error or critical unless they opt-in from their own code, unless the library has no way of expressing the failure condition through the language.
1 parent 328ef17 commit 03a066f

File tree

3 files changed

+8
-8
lines changed

3 files changed

+8
-8
lines changed

Sources/RediStack/ConnectionPool/ConnectionPool.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ extension ConnectionPool {
246246
private func connectionCreationFailed(_ error: Error, backoff: TimeAmount, logger: Logger) {
247247
self.loop.assertInEventLoop()
248248

249-
logger.error("failed to create connection for pool", metadata: [
249+
logger.warning("failed to create connection for pool", metadata: [
250250
RedisLogging.MetadataKeys.error: "\(error)"
251251
])
252252

Sources/RediStack/RedisConnection.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ public final class RedisConnection: RedisClient, RedisClientWithUserContext {
180180
guard self.state.isConnected else { return }
181181

182182
self.state = .closed
183-
self.logger.error("connection was closed unexpectedly")
183+
self.logger.warning("connection was closed unexpectedly")
184184
RedisMetrics.activeConnectionCount.decrement()
185185
}
186186

@@ -239,7 +239,7 @@ extension RedisConnection {
239239
// log data based on the result
240240
switch result {
241241
case let .failure(error):
242-
logger.error("command failed", metadata: [
242+
logger.debug("command failed", metadata: [
243243
RedisLogging.MetadataKeys.error: "\(error.localizedDescription)"
244244
])
245245

@@ -300,7 +300,7 @@ extension RedisConnection {
300300
.flatMap { self.closeChannel() } // close the channel from our end
301301

302302
notification.whenFailure {
303-
logger.error("error while closing connection", metadata: [
303+
logger.warning("failed to close connection", metadata: [
304304
RedisLogging.MetadataKeys.error: "\($0)"
305305
])
306306
}

docs/api-design/Logging.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -57,11 +57,11 @@ connection
5757
1. All log metadata keys should be added to the `RedisLogging` namespace
5858
1. Log messages should be in all lowercase, with no punctuation preferred
5959
- if a Redis command keyword (such as `QUIT`) is in the log message, it should be in all caps
60-
1. Log a `critical` message before any `precondition` failure
61-
1. Prefer single locations of `error` messages
62-
- for example, only the top level `send` command on `RedisConnection` should log the error returned from Redis or from a failed `EventLoopFuture`
63-
1. `warning` logs should be reserved for situations that could lead to `critical` conditions
60+
1. `warning` logs should be reserved for situations that could lead to `error` or `critical` conditions
6461
- this may include leaks or bad state
62+
1. Only use `error` in situations where the error cannot be expressed by the language, such as by throwing an error or failing `EventLoopFuture`s.
63+
- this is to avoid high severity logs that developers cannot control and must create filtering mechanisms if they want to ignore emitted logs from **RediStack**
64+
1. Log a `critical` message before any `preconditionFailure` or `fatalError`
6565

6666
### Metadata
6767

0 commit comments

Comments
 (0)