Skip to content

Commit b98295b

Browse files
committed
Make logging a bit more pleasant by not spewing out super-long messages
1 parent 62a1787 commit b98295b

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

WebViewJavascriptBridge/WebViewJavascriptBridge.m

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,13 @@ - (void)_queueMessage:(NSDictionary *)message {
9898

9999
- (void)_dispatchMessage:(NSDictionary *)message {
100100
NSString *messageJSON = [self _serializeMessage:message];
101-
if (logging) { NSLog(@"WVJB: send %@", messageJSON); }
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+
}
102108
messageJSON = [messageJSON stringByReplacingOccurrencesOfString:@"\\" withString:@"\\\\"];
103109
messageJSON = [messageJSON stringByReplacingOccurrencesOfString:@"\"" withString:@"\\\""];
104110
messageJSON = [messageJSON stringByReplacingOccurrencesOfString:@"\'" withString:@"\\\'"];

0 commit comments

Comments
 (0)