Skip to content

Commit b468191

Browse files
marksandsfreak4pc
authored andcommitted
Move request logging to static URLSession property
1 parent a4030e3 commit b468191

File tree

7 files changed

+17
-48
lines changed

7 files changed

+17
-48
lines changed

.github/workflows/tests.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: RxSwift
22

3-
on: [push, pull_request]
3+
on: [push, pull_request, workflow_dispatch]
44

55
jobs:
66
cocoa:

.jazzy.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ custom_categories:
1616
- KVORepresentable+CoreGraphics
1717
- KVORepresentable+Swift
1818
- KVORepresentable
19-
- Logging
2019
- NSObject+Rx+KVORepresentable
2120
- NSObject+Rx+RawRepresentable
2221
- NSObject+Rx

Documentation/GettingStarted.md

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1089,20 +1089,12 @@ URLSession.shared.rx.response(myURLRequest)
10891089
```
10901090
### Logging HTTP traffic
10911091

1092-
In debug mode RxCocoa will log all HTTP request to console by default. In case you want to change that behavior, please set `Logging.URLRequests` filter.
1092+
RxCocoa will log all HTTP request info to the console by default when run in debug mode. You may overwrite the `URLSession.rx.shouldLogRequest` closure to define which requests should and shouldn't be logged.
10931093

10941094
```swift
1095-
// read your own configuration
1096-
public struct Logging {
1097-
public typealias LogURLRequest = (URLRequest) -> Bool
1098-
1099-
public static var URLRequests: LogURLRequest = { _ in
1100-
#if DEBUG
1101-
return true
1102-
#else
1103-
return false
1104-
#endif
1105-
}
1095+
URLSession.rx.shouldLogRequest = { request in
1096+
// Only log requests to reactivex.org
1097+
return request.url?.host == "reactivex.org" || request.url?.host == "www.reactivex.org"
11061098
}
11071099
```
11081100

Rx.xcodeproj/project.pbxproj

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,6 @@
649649
C89AB2021DAAC3350065FBE6 /* KVORepresentable+CoreGraphics.swift in Sources */ = {isa = PBXBuildFile; fileRef = C89AB1BD1DAAC3350065FBE6 /* KVORepresentable+CoreGraphics.swift */; };
650650
C89AB2061DAAC3350065FBE6 /* KVORepresentable+Swift.swift in Sources */ = {isa = PBXBuildFile; fileRef = C89AB1BE1DAAC3350065FBE6 /* KVORepresentable+Swift.swift */; };
651651
C89AB20A1DAAC3350065FBE6 /* KVORepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = C89AB1BF1DAAC3350065FBE6 /* KVORepresentable.swift */; };
652-
C89AB20E1DAAC3350065FBE6 /* Logging.swift in Sources */ = {isa = PBXBuildFile; fileRef = C89AB1C01DAAC3350065FBE6 /* Logging.swift */; };
653652
C89AB2121DAAC3350065FBE6 /* NotificationCenter+Rx.swift in Sources */ = {isa = PBXBuildFile; fileRef = C89AB1C11DAAC3350065FBE6 /* NotificationCenter+Rx.swift */; };
654653
C89AB2161DAAC3350065FBE6 /* NSObject+Rx+KVORepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = C89AB1C21DAAC3350065FBE6 /* NSObject+Rx+KVORepresentable.swift */; };
655654
C89AB21A1DAAC3350065FBE6 /* NSObject+Rx+RawRepresentable.swift in Sources */ = {isa = PBXBuildFile; fileRef = C89AB1C31DAAC3350065FBE6 /* NSObject+Rx+RawRepresentable.swift */; };
@@ -1334,7 +1333,6 @@
13341333
C89AB1BD1DAAC3350065FBE6 /* KVORepresentable+CoreGraphics.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "KVORepresentable+CoreGraphics.swift"; sourceTree = "<group>"; };
13351334
C89AB1BE1DAAC3350065FBE6 /* KVORepresentable+Swift.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "KVORepresentable+Swift.swift"; sourceTree = "<group>"; };
13361335
C89AB1BF1DAAC3350065FBE6 /* KVORepresentable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = KVORepresentable.swift; sourceTree = "<group>"; };
1337-
C89AB1C01DAAC3350065FBE6 /* Logging.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = Logging.swift; sourceTree = "<group>"; };
13381336
C89AB1C11DAAC3350065FBE6 /* NotificationCenter+Rx.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = "NotificationCenter+Rx.swift"; sourceTree = "<group>"; };
13391337
C89AB1C21DAAC3350065FBE6 /* NSObject+Rx+KVORepresentable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = "NSObject+Rx+KVORepresentable.swift"; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
13401338
C89AB1C31DAAC3350065FBE6 /* NSObject+Rx+RawRepresentable.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; lineEnding = 0; path = "NSObject+Rx+RawRepresentable.swift"; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.swift; };
@@ -2312,7 +2310,6 @@
23122310
C89AB1BD1DAAC3350065FBE6 /* KVORepresentable+CoreGraphics.swift */,
23132311
C89AB1BE1DAAC3350065FBE6 /* KVORepresentable+Swift.swift */,
23142312
C89AB1BF1DAAC3350065FBE6 /* KVORepresentable.swift */,
2315-
C89AB1C01DAAC3350065FBE6 /* Logging.swift */,
23162313
C89AB1C11DAAC3350065FBE6 /* NotificationCenter+Rx.swift */,
23172314
C89AB1C21DAAC3350065FBE6 /* NSObject+Rx+KVORepresentable.swift */,
23182315
C89AB1C31DAAC3350065FBE6 /* NSObject+Rx+RawRepresentable.swift */,
@@ -2967,7 +2964,6 @@
29672964
C882542F1B8A752B00B02D69 /* UIScrollView+Rx.swift in Sources */,
29682965
C83E39822189066F001F4F0E /* NSSlider+Rx.swift in Sources */,
29692966
844BC8B41CE4FD7500F5C7CB /* UIPickerView+Rx.swift in Sources */,
2970-
C89AB20E1DAAC3350065FBE6 /* Logging.swift in Sources */,
29712967
C83E39802189066F001F4F0E /* NSControl+Rx.swift in Sources */,
29722968
C8093EE31B8A732E0088E94D /* DelegateProxyType.swift in Sources */,
29732969
C8093EFD1B8A732E0088E94D /* RxTarget.swift in Sources */,

RxCocoa/Foundation/Logging.swift

Lines changed: 0 additions & 27 deletions
This file was deleted.

RxCocoa/Foundation/URLSession+Rx.swift

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ extension Reactive where Base: URLSession {
114114
// smart compiler should be able to optimize this out
115115
let d: Date?
116116

117-
if Logging.URLRequests(request) {
117+
if URLSession.rx.shouldLogRequest(request) {
118118
d = Date()
119119
}
120120
else {
@@ -123,7 +123,7 @@ extension Reactive where Base: URLSession {
123123

124124
let task = self.base.dataTask(with: request) { data, response, error in
125125

126-
if Logging.URLRequests(request) {
126+
if URLSession.rx.shouldLogRequest(request) {
127127
let interval = Date().timeIntervalSince(d ?? Date())
128128
print(convertURLRequestToCurlCommand(request))
129129
#if os(Linux)
@@ -228,3 +228,13 @@ extension Reactive where Base: URLSession {
228228
}
229229
}
230230

231+
extension Reactive where Base == URLSession {
232+
/// Log URL requests to standard output in curl format.
233+
public static var shouldLogRequest: (URLRequest) -> Bool = { _ in
234+
#if DEBUG
235+
return true
236+
#else
237+
return false
238+
#endif
239+
}
240+
}

Sources/RxCocoa/Logging.swift

Lines changed: 0 additions & 1 deletion
This file was deleted.

0 commit comments

Comments
 (0)