From c71bbb0057a5e540cd5d382711b277a6a87201c8 Mon Sep 17 00:00:00 2001 From: Rick Hanlon Date: Mon, 7 Oct 2019 11:42:14 -0700 Subject: [PATCH] Report logs in dev to server on iOS Summary: This diff adds server side logging for all log levels in development (some levels sampled) There are two new mobile analytic event pipelines (that pipe to scuba table) - rn_dev_logs ([pigeon](https://our.intern.facebook.com/intern/marauder/event/?name=rn_dev_logs) [scuba](https://fburl.com/scuba/pqxl6mf5)) - rn_dev_logs_sampled ([pigeon](https://our.intern.facebook.com/intern/marauder/event/?name=rn_dev_logs_sampled) [scuba](https://fburl.com/scuba/oqz6b5x3)) Notes: - All React Native logs from JS and Native on iOS go through this path to be printed to the console, so everything will be caputured even though native errors/warnings do not necessarily show a red/yellow box - All errors and warnings are logged - Log level info is sampled Reviewed By: sammy-SC Differential Revision: D17789494 fbshipit-source-id: dea6359237dbd91f267949f5185a0c79bb4083b8 --- React/Base/RCTLog.h | 10 ++++++++++ React/Base/RCTLog.mm | 19 +++++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/React/Base/RCTLog.h b/React/Base/RCTLog.h index 3477b48c616deb..c00716b3af2dd4 100644 --- a/React/Base/RCTLog.h +++ b/React/Base/RCTLog.h @@ -78,6 +78,16 @@ RCT_EXTERN NSString *RCTFormatLog( NSString *message ); +/** + * A method to generate a string RCTLogLevel + */ +RCT_EXTERN NSString *RCTFormatLogLevel(RCTLogLevel); + +/** + * A method to generate a string from a RCTLogSource + */ +RCT_EXTERN NSString *RCTFormatLogSource(RCTLogSource); + /** * The default logging function used by RCTLogXX. */ diff --git a/React/Base/RCTLog.mm b/React/Base/RCTLog.mm index c6d08f6f131e39..3846ed5c4a280e 100644 --- a/React/Base/RCTLog.mm +++ b/React/Base/RCTLog.mm @@ -162,6 +162,25 @@ void RCTPerformBlockWithLogPrefix(void (^block)(void), NSString *prefix) return log; } +NSString *RCTFormatLogLevel(RCTLogLevel level) +{ + NSDictionary *levelsToString = @{@(RCTLogLevelTrace) : @"trace", + @(RCTLogLevelInfo) : @"info", + @(RCTLogLevelWarning) : @"warning", + @(RCTLogLevelFatal) : @"fatal", + @(RCTLogLevelError) : @"error"}; + + return levelsToString[@(level)]; +} + +NSString *RCTFormatLogSource(RCTLogSource source) +{ + NSDictionary *sourcesToString = @{@(RCTLogSourceNative) : @"native", + @(RCTLogSourceJavaScript) : @"js"}; + + return sourcesToString[@(source)]; +} + static NSRegularExpression *nativeStackFrameRegex() { static dispatch_once_t onceToken;