18
18
// limitations under the License.
19
19
//
20
20
21
+ #import < objc/runtime.h>
21
22
#import " RKHTTPRequestOperation.h"
22
23
#import " RKLog.h"
23
24
#import " lcl_RK.h"
@@ -126,9 +127,17 @@ - (void)dealloc
126
127
[[NSNotificationCenter defaultCenter ] removeObserver: self ];
127
128
}
128
129
130
+ static void *RKHTTPRequestOperationStartDate = &RKHTTPRequestOperationStartDate;
131
+
129
132
- (void )HTTPOperationDidStart : (NSNotification *)notification
130
133
{
131
134
RKHTTPRequestOperation *operation = [notification object ];
135
+
136
+ if (![operation isKindOfClass: [AFHTTPRequestOperation class ]]) {
137
+ return ;
138
+ }
139
+
140
+ objc_setAssociatedObject (operation, RKHTTPRequestOperationStartDate, [NSDate date ], OBJC_ASSOCIATION_RETAIN_NONATOMIC );
132
141
133
142
if ((_RKlcl_component_level[(__RKlcl_log_symbol (RKlcl_cRestKitNetwork))]) >= (__RKlcl_log_symbol (RKlcl_vTrace))) {
134
143
NSString *body = nil ;
@@ -147,19 +156,27 @@ - (void)HTTPOperationDidStart:(NSNotification *)notification
147
156
- (void )HTTPOperationDidFinish : (NSNotification *)notification
148
157
{
149
158
RKHTTPRequestOperation *operation = [notification object ];
159
+
160
+ if (![operation isKindOfClass: [AFHTTPRequestOperation class ]]) {
161
+ return ;
162
+ }
163
+
164
+ NSTimeInterval elapsedTime = [[NSDate date ] timeIntervalSinceDate: objc_getAssociatedObject (operation, RKHTTPRequestOperationStartDate)];
165
+
150
166
NSString *statusCodeString = RKStringFromStatusCode ([operation.response statusCode ]);
151
- NSString *statusCodeFragment = statusCodeString ? [NSString stringWithFormat: @" (%ld %@ )" , (long )[operation.response statusCode ], statusCodeString] : [NSString stringWithFormat: @" (%ld )" , (long )[operation.response statusCode ]];
167
+ NSString *elapsedTimeString = [NSString stringWithFormat: @" [%.04f s]" , elapsedTime];
168
+ NSString *statusCodeAndElapsedTime = statusCodeString ? [NSString stringWithFormat: @" (%ld %@ ) %@ " , (long )[operation.response statusCode ], statusCodeString, elapsedTimeString] : [NSString stringWithFormat: @" (%ld ) %@ " , (long )[operation.response statusCode ], elapsedTimeString];
152
169
if (operation.error ) {
153
170
if ((_RKlcl_component_level[(__RKlcl_log_symbol (RKlcl_cRestKitNetwork))]) >= (__RKlcl_log_symbol (RKlcl_vTrace))) {
154
- RKLogError (@" %@ '%@ ' %@ :\n error=%@ \n response.body=%@ " , [operation.request HTTPMethod ], [[operation.request URL ] absoluteString ], statusCodeFragment , operation.error , operation.responseString );
171
+ RKLogError (@" %@ '%@ ' %@ :\n error=%@ \n response.body=%@ " , [operation.request HTTPMethod ], [[operation.request URL ] absoluteString ], statusCodeAndElapsedTime , operation.error , operation.responseString );
155
172
} else {
156
- RKLogError (@" %@ '%@ ' %@ : %@ " , [operation.request HTTPMethod ], [[operation.request URL ] absoluteString ], statusCodeFragment , operation.error );
173
+ RKLogError (@" %@ '%@ ' %@ : %@ " , [operation.request HTTPMethod ], [[operation.request URL ] absoluteString ], statusCodeAndElapsedTime , operation.error );
157
174
}
158
175
} else {
159
176
if ((_RKlcl_component_level[(__RKlcl_log_symbol (RKlcl_cRestKitNetwork))]) >= (__RKlcl_log_symbol (RKlcl_vTrace))) {
160
- RKLogTrace (@" %@ '%@ ' %@ :\n response.headers=%@ \n response.body=%@ " , [operation.request HTTPMethod ], [[operation.request URL ] absoluteString ], statusCodeFragment , [operation.response allHeaderFields ], RKLogTruncateString (operation.responseString ));
177
+ RKLogTrace (@" %@ '%@ ' %@ :\n response.headers=%@ \n response.body=%@ " , [operation.request HTTPMethod ], [[operation.request URL ] absoluteString ], statusCodeAndElapsedTime , [operation.response allHeaderFields ], RKLogTruncateString (operation.responseString ));
161
178
} else {
162
- RKLogInfo (@" %@ '%@ ' %@ " , [operation.request HTTPMethod ], [[operation.request URL ] absoluteString ], statusCodeFragment );
179
+ RKLogInfo (@" %@ '%@ ' %@ " , [operation.request HTTPMethod ], [[operation.request URL ] absoluteString ], statusCodeAndElapsedTime );
163
180
}
164
181
}
165
182
}
0 commit comments