File tree Expand file tree Collapse file tree 3 files changed +20
-1
lines changed
RESTAPI.xcodeproj/xcshareddata/xcschemes Expand file tree Collapse file tree 3 files changed +20
-1
lines changed Original file line number Diff line number Diff line change @@ -161,7 +161,9 @@ var sessionAuthenticator: RequestAuthenticator {
161
161
162
162
# Debugging
163
163
164
- To turn on logging add ` APIErrorLoggingEnabled ` to 'Arguments passed on launch' at Schema/Run/Arguments
164
+ To turn on request logging add ` APIRequestLoggingEnabled ` to 'Arguments passed on launch' at Schema/Run/Arguments.
165
+
166
+ To log server sent errrors turn on ` APIErrorLoggingEnabled ` .
165
167
166
168
# TODO list
167
169
Original file line number Diff line number Diff line change 26
26
buildConfiguration = " Debug"
27
27
selectedDebuggerIdentifier = " Xcode.DebuggerFoundation.Debugger.LLDB"
28
28
selectedLauncherIdentifier = " Xcode.DebuggerFoundation.Launcher.LLDB"
29
+ language = " "
29
30
shouldUseLaunchSchemeArgsEnv = " YES" >
30
31
<Testables >
31
32
<TestableReference
55
56
buildConfiguration = " Debug"
56
57
selectedDebuggerIdentifier = " Xcode.DebuggerFoundation.Debugger.LLDB"
57
58
selectedLauncherIdentifier = " Xcode.DebuggerFoundation.Launcher.LLDB"
59
+ language = " "
58
60
launchStyle = " 0"
59
61
useCustomWorkingDirectory = " NO"
60
62
ignoresPersistentStateOnLaunch = " NO"
75
77
argument = " APIErrorLoggingEnabled"
76
78
isEnabled = " YES" >
77
79
</CommandLineArgument >
80
+ <CommandLineArgument
81
+ argument = " APIRequestLoggingEnabled"
82
+ isEnabled = " YES" >
83
+ </CommandLineArgument >
78
84
</CommandLineArguments >
79
85
<AdditionalOptions >
80
86
</AdditionalOptions >
Original file line number Diff line number Diff line change @@ -221,6 +221,17 @@ internal extension API {
221
221
request. httpMethod = method
222
222
223
223
let session = URLSession ( configuration: URLSessionConfiguration . default)
224
+ if ProcessInfo . processInfo. arguments. contains ( " APIRequestLoggingEnabled " ) {
225
+ let loggedRequest = authentication. authenticateURLRequest ( request)
226
+ print ( " \n \( loggedRequest. httpMethod ?? " No http method " ) \( loggedRequest. url? . absoluteString ?? " No URL " ) " )
227
+ print ( " HEADERS: \n \( loggedRequest. allHTTPHeaderFields? . reduce ( " " , { return $0 + " \t \( $1. key) : \( $1. value) \n " } ) ?? " No header fields " ) " )
228
+ if let body = loggedRequest. httpBody {
229
+ print ( " BODY: \n \( String ( data: body, encoding: . utf8) ?? " Cannot parse request body " ) " )
230
+ }
231
+ else {
232
+ print ( " Empty request body " )
233
+ }
234
+ }
224
235
session. dataTask ( with: authentication. authenticateURLRequest ( request) as URLRequest ,
225
236
completionHandler: { ( data, response, error) -> Void in
226
237
if let err = APIError ( withResponse: response) , ProcessInfo . processInfo. arguments. contains ( " APIErrorLoggingEnabled " ) {
You can’t perform that action at this time.
0 commit comments