Short description of the issue:
When using URLSession+Rx there is constant logging of responses in DEBUG mode, like below:
curl -X POST
-H "Accept: */*"
-H "Content-Type: multipart/form-data; boundary=Boundary+831b5b4241e692bf"
"http://example.com/upload-image/" -i -v
Success (1660ms): Status 200
curl -X POST
-H "Accept: */*"
-H "Content-Type: multipart/form-data; boundary=Boundary+c93de5352cdf7ffd"
"http://example.com/upload-image/" -i -v
Success (9105ms): Status 200
Unfortunately there is no ability to turn this off, without changing library inner code.
Expected outcome:
It would be great if there will be some flag or log-policy attribute, to be able to turn this logging off even in debug mode.
What actually happens:
It happens in file URLSession+Rx. There is this code:
let task = self.base.dataTask(with: request) { (data, response, error) in
if Logging.URLRequests(request) {
let interval = Date().timeIntervalSince(d ?? Date())
print(convertURLRequestToCurlCommand(request))
#if os(Linux)
print(convertResponseToString(response, error.flatMap { $0 as? NSError }, interval))
#else
print(convertResponseToString(response, error.map { $0 as NSError }, interval))
#endif
}
...
If you jump to definition of Logging.URLRequests, you will see that it always returns true for DEBUG mode and false for RELEASE:
public struct Logging {
public typealias LogURLRequest = (URLRequest) -> Bool
/// Log URL requests to standard output in curl format.
public static var URLRequests: LogURLRequest = { _ in
#if DEBUG
return true
#else
return false
#endif
}
}
RxSwift/RxCocoa/RxBlocking/RxTest version/commit
RxSwift 4.1.2
Platform/Environment
How easy is to reproduce? (chances of successful reproduce after running the self contained code)
Xcode version:
Version 9.3 (9E145)
Installation method:
I have multiple versions of Xcode installed:
(so we can know if this is a potential cause of your issue)
Level of RxSwift knowledge:
(this is so we can understand your level of knowledge
and formulate the response in an appropriate manner)
Logging.URLRequests = { _ in false };
How do you disable this in 6.0.0?
It's in the README:
URLSession.rx.shouldLogRequest = { request in
return false // Or use request to determine if you want to log or not
}
Found it just as you replied :)
Most helpful comment