Skip to content

Commit c317a70

Browse files
sota000facebook-github-bot
authored andcommitted
Add a way to bind log function to the unified react native logger.
Summary: In this diff: 1. Convert the ReactNativeLogger to c function for the future compatibility. 2. Bind the log function from Catalyst app 3. Update the call site Changelog: [internal] Reviewed By: JoshuaGross Differential Revision: D30271863 fbshipit-source-id: 4c0ea704cf19f53468a3b72631353959ea999884
1 parent 3e5998e commit c317a70

File tree

6 files changed

+88
-54
lines changed

6 files changed

+88
-54
lines changed

ReactCommon/react/renderer/components/view/BUCK

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ rn_xplat_cxx_library(
6464
react_native_xplat_target("react/renderer/core:core"),
6565
react_native_xplat_target("react/renderer/debug:debug"),
6666
react_native_xplat_target("react/renderer/graphics:graphics"),
67+
react_native_xplat_target("react/utils:utils"),
6768
],
6869
)
6970

ReactCommon/react/renderer/components/view/YogaLayoutableShadowNode.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
#include <react/renderer/core/LayoutContext.h>
1515
#include <react/renderer/debug/DebugStringConvertibleItem.h>
1616
#include <react/renderer/debug/SystraceSection.h>
17-
#include <react/utils/ReactNativeLogger.h>
17+
#include <react/utils/react_native_log.h>
1818
#include <yoga/Yoga.h>
1919
#include <algorithm>
2020
#include <limits>
@@ -227,7 +227,7 @@ void YogaLayoutableShadowNode::appendChild(
227227

228228
ensureConsistency();
229229
} else {
230-
ReactNativeLogger::error(
230+
react_native_log_error(
231231
"Text strings must be rendered within a <Text> component.");
232232
}
233233
}

ReactCommon/react/utils/ReactNativeLogger.cpp

Lines changed: 0 additions & 29 deletions
This file was deleted.

ReactCommon/react/utils/ReactNativeLogger.h

Lines changed: 0 additions & 23 deletions
This file was deleted.
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#include "react_native_log.h"
9+
#include <glog/logging.h>
10+
11+
static reactnativelogfunctype _reactnativelogfunc = NULL;
12+
13+
void set_react_native_logfunc(reactnativelogfunctype newlogfunc) {
14+
_reactnativelogfunc = newlogfunc;
15+
}
16+
void react_native_log_info(const char *message) {
17+
_react_native_log(ReactNativeLogLevelInfo, message);
18+
}
19+
void react_native_log_warn(const char *message) {
20+
_react_native_log(ReactNativeLogLevelWarning, message);
21+
}
22+
void react_native_log_error(const char *message) {
23+
_react_native_log(ReactNativeLogLevelError, message);
24+
}
25+
void react_native_log_fatal(const char *message) {
26+
_react_native_log(ReactNativeLogLevelFatal, message);
27+
}
28+
29+
void _react_native_log(ReactNativeLogLevel level, const char *message) {
30+
if (_reactnativelogfunc == NULL) {
31+
_react_native_log_default(level, message);
32+
} else {
33+
_reactnativelogfunc(level, message);
34+
}
35+
}
36+
37+
void _react_native_log_default(ReactNativeLogLevel level, const char *message) {
38+
switch (level) {
39+
case ReactNativeLogLevelInfo:
40+
LOG(INFO) << message;
41+
break;
42+
case ReactNativeLogLevelWarning:
43+
LOG(WARNING) << message;
44+
break;
45+
case ReactNativeLogLevelError:
46+
LOG(ERROR) << message;
47+
break;
48+
case ReactNativeLogLevelFatal:
49+
LOG(FATAL) << message;
50+
break;
51+
}
52+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
/*
2+
* Copyright (c) Facebook, Inc. and its affiliates.
3+
*
4+
* This source code is licensed under the MIT license found in the
5+
* LICENSE file in the root directory of this source tree.
6+
*/
7+
8+
#pragma once
9+
10+
enum ReactNativeLogLevel {
11+
ReactNativeLogLevelInfo = 1,
12+
ReactNativeLogLevelWarning = 2,
13+
ReactNativeLogLevelError = 3,
14+
ReactNativeLogLevelFatal = 4
15+
};
16+
17+
typedef void (*reactnativelogfunctype)(ReactNativeLogLevel, const char *);
18+
19+
#ifdef __cplusplus
20+
extern "C" {
21+
#endif // __cplusplus
22+
void set_react_native_logfunc(reactnativelogfunctype newlogfunc);
23+
24+
void react_native_log_info(const char *text);
25+
void react_native_log_warn(const char *text);
26+
void react_native_log_error(const char *text);
27+
void react_native_log_fatal(const char *text);
28+
29+
void _react_native_log(ReactNativeLogLevel level, const char *text);
30+
void _react_native_log_default(ReactNativeLogLevel level, const char *text);
31+
#ifdef __cplusplus
32+
}
33+
#endif // __cpusplus

0 commit comments

Comments
 (0)