I'm building a React Native native module (aka 'bridge') for iOS and Android and need to log to the JS console in native code (Objective C and Java). This is done easily in iOS using RCTLog
but I can't figure out how to do it in Java.
I tried Log.i
but those messages aren't forwarded to Javascript.
The only thing I can think of at this point is to emit a JS event from the Java module and have a handler on the JS side just call console.log
with the message but that's a pretty roundabout way of doing it.
I would expect to be able to do something like this.getReactApplicationContext().log("see me in the JS console")
but no dice. Anyone know how to do this?
It looks like as of upcoming react native 0.63
we may be getting the equivalent of iOS's RCTLog
in Android: https://github.com/facebook/react-native/commit/52b3105f652eca72892f200923e1687f1d995486
The files are in master: https://github.com/facebook/react-native/tree/master/ReactAndroid/src/main/java/com/facebook/react/util
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With