Skip to content

Commit

Permalink
feat!: Clean up logging (#1832)
Browse files Browse the repository at this point in the history
* Clean up logging

* Update test

* Update test

* Reflect changes in smithy-swift

---------

Co-authored-by: Sichan Yoo <[email protected]>
  • Loading branch information
sichanyoo and Sichan Yoo authored Dec 12, 2024
1 parent 7be8def commit 615a518
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -386,12 +386,9 @@ class TestLogger: LogAgent {

var messages: [(level: LogAgentLevel, message: String)] = []

var level: LogAgentLevel

init(name: String = "Test", messages: [(level: LogAgentLevel, message: String)] = [], level: LogAgentLevel = .info) {
self.name = name
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) {
Expand Down
29 changes: 24 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,34 @@
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
import Logging

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 more severe leveled messages get logged for S3Client.
await loggingSystem.add(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: SDKLogLevel

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

public init(logLevel: SDKLogLevel) {
self.logLevel = logLevel
}
}
```

0 comments on commit 615a518

Please sign in to comment.