Skip to content

Commit f78a99c

Browse files
committed
clean up too long log messages in all log cases
1 parent 70c3284 commit f78a99c

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

WebViewJavascriptBridge/WebViewJavascriptBridge.m

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ - (void)_queueMessage:(NSDictionary*)message;
2020
- (void)_dispatchMessage:(NSDictionary*)message;
2121
- (NSString*)_serializeMessage:(NSDictionary*)message;
2222
- (NSDictionary*)_deserializeMessageJSON:(NSString*)messageJSON;
23+
- (void)_log:(NSString*)type json:(NSString*)output;
2324

2425
@end
2526

@@ -98,13 +99,7 @@ - (void)_queueMessage:(NSDictionary *)message {
9899

99100
- (void)_dispatchMessage:(NSDictionary *)message {
100101
NSString *messageJSON = [self _serializeMessage:message];
101-
if (logging) {
102-
if (messageJSON.length > 500) {
103-
NSLog(@"WVJB: send %@", [[messageJSON substringToIndex:500] stringByAppendingString:@" [...]"]);
104-
} else {
105-
NSLog(@"WVJB: send %@", messageJSON);
106-
}
107-
}
102+
[self _log:@"send" json:messageJSON];
108103
messageJSON = [messageJSON stringByReplacingOccurrencesOfString:@"\\" withString:@"\\\\"];
109104
messageJSON = [messageJSON stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""];
110105
messageJSON = [messageJSON stringByReplacingOccurrencesOfString:@"\'" withString:@"\\\'"];
@@ -122,12 +117,12 @@ - (void)_flushMessageQueue {
122117

123118
NSString* responseId = [message objectForKey:@"responseId"];
124119
if (responseId) {
125-
if (logging) { NSLog(@"WVJB response: %@", messageJSON); }
120+
[self _log:@"response" json:messageJSON];
126121
WVJBResponseCallback responseCallback = [_responseCallbacks objectForKey:responseId];
127122
responseCallback([message objectForKey:@"error"], [message objectForKey:@"responseData"]);
128123
[_responseCallbacks removeObjectForKey:responseId];
129124
} else {
130-
if (logging) { NSLog(@"WVJB message: %@", messageJSON); }
125+
[self _log:@"messages" json:messageJSON];
131126
WVJBResponse* response = nil;
132127
if ([message objectForKey:@"callbackId"]) {
133128
response = [[WVJBResponse alloc] initWithCallbackId:[message objectForKey:@"callbackId"] bridge:self];
@@ -166,6 +161,15 @@ - (NSDictionary *)_deserializeMessageJSON:(NSString *)messageJSON {
166161
#endif
167162
}
168163

164+
- (void)_log:(NSString *)type json:(NSString *)json {
165+
if (!logging) { return; }
166+
if (json.length > 500) {
167+
NSLog(@"WVJB: %@ %@", type, [[json substringToIndex:500] stringByAppendingString:@" [...]"]);
168+
} else {
169+
NSLog(@"WVJB: %@ %@", type, json);
170+
}
171+
}
172+
169173
#pragma mark UIWebViewDelegate
170174

171175
- (void)webViewDidFinishLoad:(UIWebView *)webView {

0 commit comments

Comments
 (0)