Skip to content

Commit 896e95a

Browse files
sichanyooSichan Yoo
andauthored
chore: Misc. logging changes (#797)
* Add .none ClientLogMode and make it defualt to make logging opt-in. * Adjust logging levels for URL session HTTP client. * Add public init and set default log level for initialize() method to .error. * Fix SwiftLogger::log method to pass in the designated log level (self.level) to the underlying Logger::log method, instead of wrongly copying the log level passed into SwiftLogger::log. --------- Co-authored-by: Sichan Yoo <[email protected]>
1 parent a6d1331 commit 896e95a

File tree

7 files changed

+19
-10
lines changed

7 files changed

+19
-10
lines changed

Sources/ClientRuntime/Config/DefaultClientConfiguration.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ public protocol DefaultClientConfiguration: ClientConfiguration {
1515

1616
/// The log mode to use for client logging.
1717
///
18-
/// If none is provided, `.request` will be used.
18+
/// If none is provided, `.none` will be used.
1919
var clientLogMode: ClientLogMode { get set }
2020

2121
/// The network endpoint to use.

Sources/ClientRuntime/Config/DefaultSDKRuntimeConfiguration.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public struct DefaultSDKRuntimeConfiguration<DefaultSDKRuntimeRetryStrategy: Ret
5454

5555
/// The log mode to use for client logging.
5656
///
57-
/// If none is provided, `.request` will be used.
57+
/// If none is provided, `.none` will be used.
5858
public var clientLogMode: ClientLogMode
5959

6060
/// The network endpoint to use.
@@ -126,8 +126,8 @@ public extension DefaultSDKRuntimeConfiguration {
126126

127127
/// The log mode to use when none is provided
128128
///
129-
/// Defaults to `.request`.
130-
static var defaultClientLogMode: ClientLogMode { .requestWithoutAuthorizationHeader }
129+
/// Defaults to `.none`.
130+
static var defaultClientLogMode: ClientLogMode { .none }
131131

132132
static var defaultAuthSchemeResolver: AuthSchemeResolver { DefaultAuthSchemeResolver() }
133133
}

Sources/ClientRuntime/Networking/Http/URLSession/FoundationStreamBridge.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -281,7 +281,7 @@ class FoundationStreamBridge: NSObject, StreamDelegate {
281281
// `writeCount` will be a positive number if bytes were written.
282282
// Remove the written bytes from the front of the buffer.
283283
if writeCount > 0 {
284-
logger.info("FoundationStreamBridge: wrote \(writeCount) bytes to request body")
284+
logger.debug("FoundationStreamBridge: wrote \(writeCount) bytes to request body")
285285
buffer.removeFirst(writeCount)
286286
// TICK - smithy.client.http.bytes_sent
287287
var attributes = Attributes()

Sources/ClientRuntime/Networking/Http/URLSession/URLSessionHTTPClient.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -198,15 +198,15 @@ public final class URLSessionHTTPClient: HTTPClient {
198198
guard let tlsOptions = tlsOptions, tlsOptions.useSelfSignedCertificate,
199199
let certFile = tlsOptions.certificate,
200200
let serverTrust = challenge.protectionSpace.serverTrust else {
201-
logger.error(
201+
logger.info(
202202
"Either TLSOptions not set or missing values! Using default trust store."
203203
)
204204
completionHandler(.performDefaultHandling, nil)
205205
return
206206
}
207207

208208
guard let customRoot = Bundle.main.certificate(named: certFile) else {
209-
logger.error("Certificate not found! Using default trust store.")
209+
logger.info("Certificate not found! Using default trust store.")
210210
completionHandler(.performDefaultHandling, nil)
211211
return
212212
}
@@ -232,7 +232,7 @@ public final class URLSessionHTTPClient: HTTPClient {
232232
guard let tlsOptions, tlsOptions.useProvidedKeystore,
233233
let keystoreName = tlsOptions.pkcs12Path,
234234
let keystorePasword = tlsOptions.pkcs12Password else {
235-
logger.error(
235+
logger.info(
236236
"Either TLSOptions not set or missing values! Using default keystore."
237237
)
238238
completionHandler(.performDefaultHandling, nil)

Sources/ClientRuntime/Telemetry/Logging/ClientLogMode.swift

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
//
77

88
public enum ClientLogMode {
9+
case none
910
case request
1011
case requestWithBody
1112
case response

Sources/ClientRuntime/Telemetry/Logging/SDKLoggingSystem.swift

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,14 @@ public actor SDKLoggingSystem {
1111
private var isInitialized = false
1212
private var factories: [String: SDKLogHandlerFactory] = [:]
1313

14+
public init() {}
15+
1416
public func add(logHandlerFactory: SDKLogHandlerFactory) {
1517
let label = logHandlerFactory.label
1618
factories[label] = logHandlerFactory
1719
}
1820

19-
public func initialize(defaultLogLevel: SDKLogLevel = .info) async {
21+
public func initialize(defaultLogLevel: SDKLogLevel = .error) async {
2022
if isInitialized { return } else { isInitialized = true }
2123
let ptr = factories
2224
LoggingSystem.bootstrap { label in

Sources/Smithy/Logging/SwiftLog+LogAgent.swift

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,12 @@ public struct SwiftLogger: LogAgent {
1616
self.logLevel = LogAgentLevel.info
1717
}
1818

19+
public init(label: String, logLevel: LogAgentLevel) {
20+
self.label = label
21+
self.logger = Logger(label: label)
22+
self.logLevel = logLevel
23+
}
24+
1925
public var level: LogAgentLevel {
2026
get {
2127
return logLevel
@@ -39,7 +45,7 @@ public struct SwiftLogger: LogAgent {
3945
let mappedDict = metadata?.mapValues { (value) -> Logger.MetadataValue in
4046
return Logger.MetadataValue.string(value)
4147
}
42-
self.logger.log(level: logLevel.toLoggerLevel(),
48+
self.logger.log(level: level.toLoggerLevel(),
4349
Logger.Message(stringLiteral: message),
4450
metadata: mappedDict,
4551
source: source,

0 commit comments

Comments
 (0)