Skip to content

Commit

Permalink
Silence annoying logs in iOS 11
Browse files Browse the repository at this point in the history
Summary: Apple changed what messages get logged when a web socket connection fails. Lets hide them to make life better for engineers.

Reviewed By: javache

Differential Revision: D5879306

fbshipit-source-id: cde06405b4af251159269218bf922916a79ac840
  • Loading branch information
Mehdi Mulani authored and facebook-github-bot committed Sep 21, 2017
1 parent 6ce69dc commit f01c73d
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion Libraries/WebSocket/RCTReconnectingWebSocket.m
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,10 @@
#import <React/RCTDefines.h>
#import <fishhook/fishhook.h>

#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */
#import <os/log.h>
#endif /* __IPHONE_11_0 */

#import "RCTSRWebSocket.h"

#if RCT_DEV // Only supported in dev mode
Expand All @@ -27,11 +31,25 @@ static void my_nwlog_legacy_v(int level, char *format, va_list args) {
vsnprintf(buffer, buffer_size, format, copy);
va_end(copy);

if (strstr(buffer, "nw_connection_get_connected_socket_block_invoke") == NULL) {
if (strstr(buffer, "nw_connection_get_connected_socket_block_invoke") == NULL &&
strstr(buffer, "Connection has no connected handler") == NULL) {
orig_nwlog_legacy_v(level, format, args);
}
}

#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */

static void (*orig_os_log_error_impl)(void *dso, os_log_t log, os_log_type_t type, const char *format, uint8_t *buf, uint32_t size);

static void my_os_log_error_impl(void *dso, os_log_t log, os_log_type_t type, const char *format, uint8_t *buf, uint32_t size)
{
if (strstr(format, "TCP Conn %p Failed : error %ld:%d") == NULL) {
orig_os_log_error_impl(dso, log, type, format, buf, size);
}
}

#endif /* __IPHONE_11_0 */

@interface RCTReconnectingWebSocket () <RCTSRWebSocketDelegate>
@end

Expand All @@ -49,6 +67,11 @@ + (void)load
rebind_symbols((struct rebinding[1]){
{"nwlog_legacy_v", my_nwlog_legacy_v, (void *)&orig_nwlog_legacy_v}
}, 1);
#if defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 110000 /* __IPHONE_11_0 */
rebind_symbols((struct rebinding[1]){
{"_os_log_error_impl", my_os_log_error_impl, (void *)&orig_os_log_error_impl}
}, 1);
#endif /* __IPHONE_11_0 */
});
}

Expand Down

0 comments on commit f01c73d

Please sign in to comment.