66import Alamofire
77import Foundation
88
9- public protocol HTTPClientLogger {
9+ public protocol HTTPClientLogger : Sendable {
1010
1111 /// Request was formed with provided options and headers.
1212 /// Called before adding validator/serializers to said request and starting it.
@@ -63,49 +63,49 @@ public protocol HTTPClientLogger {
6363
6464}
6565
66- open class HTTPClientLoggerNone : HTTPClientLogger {
66+ public final class HTTPClientLoggerNone : HTTPClientLogger {
6767
6868 public init ( ) { }
6969
70- open func clientDidCreateRequest< ParserType: HTTPClientParser , EndpointType> (
70+ public func clientDidCreateRequest< ParserType: HTTPClientParser , EndpointType> (
7171 requestOptions: HTTPClientRequestOptions < ParserType , EndpointType > ,
7272 resolvedHeaders: Alamofire . HTTPHeaders ) { }
7373
74- open func clientDidReceiveResponse< ParserType: HTTPClientParser , EndpointType> (
74+ public func clientDidReceiveResponse< ParserType: HTTPClientParser , EndpointType> (
7575 requestOptions: HTTPClientRequestOptions < ParserType , EndpointType > ,
7676 request: URLRequest ? ,
7777 response: HTTPURLResponse ? ,
7878 responseData: Data ? ,
7979 responseError: Error ? ) { }
8080
81- open func requestWasCancelled< ParserType: HTTPClientParser , EndpointType> (
81+ public func requestWasCancelled< ParserType: HTTPClientParser , EndpointType> (
8282 requestOptions: HTTPClientRequestOptions < ParserType , EndpointType > ,
8383 request: URLRequest ? ,
8484 response: HTTPURLResponse ? ,
8585 responseData: Data ? ) { }
8686
87- open func parserDidFindError< ParserType: HTTPClientParser , EndpointType> (
87+ public func parserDidFindError< ParserType: HTTPClientParser , EndpointType> (
8888 requestOptions: HTTPClientRequestOptions < ParserType , EndpointType > ,
8989 request: URLRequest ? ,
9090 response: HTTPURLResponse ? ,
9191 responseData: Data ? ,
9292 parsedError: Swift . Error ) { }
9393
94- open func clientDidEncounterNetworkError< ParserType: HTTPClientParser , EndpointType> (
94+ public func clientDidEncounterNetworkError< ParserType: HTTPClientParser , EndpointType> (
9595 requestOptions: HTTPClientRequestOptions < ParserType , EndpointType > ,
9696 request: URLRequest ? ,
9797 response: HTTPURLResponse ? ,
9898 responseData: Data ? ,
9999 networkError: Swift . Error ) { }
100100
101- open func clientDidEncounterSerializationError< ParserType: HTTPClientParser , EndpointType> (
101+ public func clientDidEncounterSerializationError< ParserType: HTTPClientParser , EndpointType> (
102102 requestOptions: HTTPClientRequestOptions < ParserType , EndpointType > ,
103103 request: URLRequest ? ,
104104 response: HTTPURLResponse ? ,
105105 responseData: Data ? ,
106106 serializationError: Swift . Error ) { }
107107
108- open func clientDidEncounterParseError< ParserType: HTTPClientParser , EndpointType> (
108+ public func clientDidEncounterParseError< ParserType: HTTPClientParser , EndpointType> (
109109 requestOptions: HTTPClientRequestOptions < ParserType , EndpointType > ,
110110 request: URLRequest ? ,
111111 response: HTTPURLResponse ? ,
@@ -115,11 +115,12 @@ open class HTTPClientLoggerNone: HTTPClientLogger {
115115}
116116
117117/// Full logger, intended for subclassing to provide actual method to output logs.
118- open class HTTPClientLoggerFull {
118+ public final class HTTPClientLoggerFull {
119119
120120 private let tab : String
121121 private let parametersToCensor : [ String ]
122122 private let censoredValue : String
123+ private let logAction : @Sendable ( _ message: String ) -> Void
123124
124125 /// - parameter tab: value used for indentation in multiline messages.
125126 /// Default value is ` ` (4 spaces).
@@ -130,14 +131,12 @@ open class HTTPClientLoggerFull {
130131 /// Default value is `xxxxxx`.
131132 public init ( tab: String = " " ,
132133 parametersToCensor: [ String ] = [ ] ,
133- censoredValue: String = " xxxxxx " ) {
134+ censoredValue: String = " xxxxxx " ,
135+ logAction: @escaping @Sendable ( _ message: String ) -> Void ) {
134136 self . tab = tab
135137 self . parametersToCensor = parametersToCensor
136138 self . censoredValue = censoredValue
137- }
138-
139- open func log( _ message: String ) {
140- fatalError ( " abstract " )
139+ self . logAction = logAction
141140 }
142141
143142 private func censorParameters( _ parameters: [ String : any Any & Sendable ] ) -> [ String : any Any & Sendable ] {
@@ -148,7 +147,7 @@ open class HTTPClientLoggerFull {
148147 return censoredParameters
149148 }
150149
151- open func generateResponseDataDebugDescription( _ responseData: Data ? ) -> String ? {
150+ public func generateResponseDataDebugDescription( _ responseData: Data ? ) -> String ? {
152151 guard let data = responseData, !data. isEmpty else {
153152 return nil
154153 }
@@ -197,7 +196,7 @@ extension HTTPClientLoggerFull: HTTPClientLogger {
197196 requestDescription. append ( " \n \( tab) authCredential: \( credentialForLog) " )
198197 }
199198
200- log ( requestDescription)
199+ logAction ( requestDescription)
201200 }
202201
203202 public func clientDidReceiveResponse< ParserType: HTTPClientParser , EndpointType> (
@@ -234,7 +233,7 @@ extension HTTPClientLoggerFull: HTTPClientLogger {
234233 responseDescription. append ( " \n \( tab) headers: \n \( responseHeaderDescription) " )
235234 responseDescription. append ( " \n \( tab) data: \n \( responseDataDescription) " )
236235
237- log ( responseDescription)
236+ logAction ( responseDescription)
238237 }
239238
240239 public func requestWasCancelled< ParserType: HTTPClientParser , EndpointType> (
0 commit comments