Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

console.log doesn't work with react-native

I'm starting with react-native and I'm getting this problem: I can't log to bundler metro server.

If I create my application using create-react-native-app, I can do 'console.log' and value are logged to metro bundler (running on port 8081).

But if I create my application with react-native init <project>, this doesn't work. To make console.log work, I need to open Chrome DevTools and set remote debug in application.

So my question is: is there any way to make native code to log in bundler console with console.log? I don't want to work with 'create-react-native-app' because it uses Expo and 'realm' database doesn't support expo.

I've tried with react-native 0.55.4 and 0.56, both in windows and linux.

like image 456
Jonis Maurin Ceará Avatar asked Jul 16 '18 18:07

Jonis Maurin Ceará


5 Answers

You can also see the console.log() outputs using these commands:

$ react-native log-android
$ react-native log-ios

Note: It also works to debug native errors, for example when you have a blank screen and metro bundler doesn't show errors neither.

For more information you can check this out

like image 53
David Noreña Avatar answered Oct 16 '22 09:10

David Noreña


Don't know if I correctly understand your question (because of my english), but you can try this:

Run adb logcat *:S ReactNative:V ReactNativeJS:V in a terminal to see your Android app's logs.

Taken from Using adb logcat for React Native Debugging

like image 23
SuperSec Avatar answered Oct 16 '22 08:10

SuperSec


I discovered that console.log are omitted from console log if your disable remote debug from the debug menu

like image 45
realtebo Avatar answered Oct 16 '22 09:10

realtebo


You can download React Native Debugger and Open your JS Debugger in development menu. You can see everything into RN Debugger.

like image 1
Atakan Avatar answered Oct 16 '22 09:10

Atakan


On Mac. While on ios simulator Clicked on

Command-d->Stop Debugging

.This made logging work for me.

like image 1
MEHMET AYDAR Avatar answered Oct 16 '22 07:10

MEHMET AYDAR