Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat!: Clean up logging #1832

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public struct FlexibleChecksumsResponseMiddleware<OperationStackInput, Operation
guard let checksumHeader = checksumHeaderIsPresent else {
let message =
"User requested checksum validation, but the response headers did not contain any valid checksums"
logger.warn(message)
logger.warning(message)
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import class SmithyStreams.BufferedStream
import class SmithyChecksums.ChunkedStream
import enum SmithyChecksums.ChecksumMismatchException
import AWSClientRuntime
import Logging

class FlexibleChecksumsMiddlewareTests: XCTestCase {
private var builtContext: Context!
Expand Down Expand Up @@ -382,19 +383,16 @@ class FlexibleChecksumsMiddlewareTests: XCTestCase {
}

class TestLogger: LogAgent {
var name: String
var label: String

var messages: [(level: LogAgentLevel, message: String)] = []
var messages: [(level: Logging.Logger.Level, message: String)] = []

var level: LogAgentLevel

init(name: String = "Test", messages: [(level: LogAgentLevel, message: String)] = [], level: LogAgentLevel = .info) {
self.name = name
init(label: String = "Test", messages: [(level: Logging.Logger.Level, message: String)] = [], level: Logging.Logger.Level = .info) {
self.label = label
self.messages = messages
self.level = level
}

func log(level: LogAgentLevel = .info, message: @autoclosure () -> String, metadata: @autoclosure () -> [String : String]? = nil, source: @autoclosure () -> String = "ChecksumUnitTests", file: String = #file, function: String = #function, line: UInt = #line) {
func log(level: Logging.Logger.Level = .info, message: @autoclosure () -> String, metadata: @autoclosure () -> [String : String]? = nil, source: @autoclosure () -> String = "ChecksumUnitTests", file: String = #file, function: String = #function, line: UInt = #line) {
messages.append((level: level, message: message()))
}
}
Expand Down
28 changes: 23 additions & 5 deletions Sources/Core/AWSSDKForSwift/Documentation.docc/logging.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,33 @@
The AWS SDK for Swift uses SwiftLog for high performant logging. Many of our calls are issued to the `debug` level of output, which are disabled in the console by default. To see debug output to your console, you can add the following code to your application in a place where you know that the code will be called once and only once:
```swift
import ClientRuntime
SDKLoggingSystem().initialize(logLevel: .debug)
await SDKLoggingSystem().initialize(logLevel: .debug)
```

Alternatively, if you need finer grain control of instances of SwiftLog, you can call `SDKLoggingSystem::add` to control specific instances of the log handler. For example:
```swift
import ClientRuntime

let system = SDKLoggingSystem()
system.add(logHandlerFactory: S3ClientLogHandlerFactory(logLevel: .debug))
system.add(logHandlerFactory: CRTClientEngineLogHandlerFactory(logLevel: .info))
system.initialize()
let loggingSystem = SDKLoggingSystem()

// Adds custom log handler for S3Client so that only .debug or severe leveled messages get logged for S3Client.
await loggingSystem.addLogHandlerFactory(logHandlerFactory: S3ClientLogHandlerFactory(logLevel: .debug))
await loggingSystem.initialize()

// Example implementation of a service-specific log handler factory.
public struct S3ClientLogHandlerFactory: SDKLogHandlerFactory {
// This label value must be the name of the service client you want the log handler to apply to.
public var label = "S3Client"
let logLevel: Logger.Level

public func construct(label: String) -> LogHandler {
var handler = StreamLogHandler.standardOutput(label: label)
handler.logLevel = logLevel
return handler
}

public init(logLevel: Logger.Level) {
self.logLevel = logLevel
}
}
```
Loading