How can I log a variable in React Native, like using console.log when developing for web?
-
Try out react-native-log-ios npm pkg, it works out of the box without remote JS debugging.anni– anni2018-11-05 12:09:53 +00:00Commented Nov 5, 2018 at 12:09
-
are you using RN to create a webb app ?nios– nios2022-11-11 07:39:36 +00:00Commented Nov 11, 2022 at 7:39
37 Answers
Use console.log, console.warn, etc.
As of React Native 0.29, you can simply run the following to see logs in the console:
react-native log-ios
react-native log-android
10 Comments
react-native log-ios evelopers-Mac-mini com.apple.CoreSimulator.SimDevice.02C1B6C7-2CD2-406E-AC93-DD430E5E3C69[948] (com.apple.videosubscriptionsd) <Notice>: Service only ran for 0 seconds. Pushing respawn out by 10 seconds.console.log will not show up.console.log works.
By default on iOS, it logs to the debug pane inside Xcode.
From the iOS simulator, press (⌘+D) and press Remote JS Debugging. This will open a resource, http://localhost:8081/debugger-ui on localhost. From there, use the Chrome Developer tools JavaScript console to view console.log
Edit 2023
You can just do console.log and it will print to the terminal you're running react-native in without any special commands
12 Comments
Pre React Native 0.29, run this in the console:
adb logcat *:S ReactNative:V ReactNativeJS:V
Post React Native 0.29, run:
react-native log-ios
or
react-native log-android
As Martin said in another answer.
This shows all console.log(), errors, notes, etc. and causes zero slow down.
4 Comments
adb logcat -v time -s ReactNativeJSreact-native log-android error Unrecognized command "log-android". react-native --version 4.14.0 adb logcat continues to work with or without react-native tools installed.Use console.debug("text");
You will see the logs inside the terminal.
Steps:
- Run the application:
react-native run-ios # For iOS
react-native run-android # For Android
- Run the logger:
react-native log-ios # For iOS
react-native log-android # For Android
2 Comments
Initializing React Xplat Bridge..This is where Chrome Developer Tools are your friend.
The following steps should get you to the Chrome Developer Tools, where you will be able to see your console.log statements.
Steps
- Install Google Chrome, if you have not already
- Run app using
react-native run-androidorreact-native run-ios - Open developer menu
- Mac:
⌘+Dfor iOS or⌘Mfor Android iOS - Windows/Linux: Shake Android phone
- Mac:
- Select
Debug JS Remotely - This should launch the debugger in Chrome
- In Chrome:
Tools -> More Tools -> Developer Optionsand make sure you are on theconsoletab
Now whenever a console.log statement is executed, it should appear in Chrome Dev Tools. The official documentation is here.
1 Comment
Visual Studio Code has a decent debug console that can show your console.log file.
Visual Studio Code is, more often than not, React Native friendly.
2 Comments
I prefer to recommend you guys using React Native Debugger. You can download and install it by using this command (Mac only).
brew update && brew cask install react-native-debugger
1 Comment
start This will open Debugger as you default debugger instead of Chrome and the -g flag will prevent it from hijacking focus on reloads. "start": "env REACT_DEBUGGER=\"$([ -d '/Applications/React Native Debugger.app' ] && echo \"open -g 'rndebugger://set-debugger-loc?host=localhost&port=8081' --args\")\" node node_modules/react-native/local-cli/cli.js start"I had the same issue: console messages were not appearing in Xcode's debug area. In my app I did Cmd + D to bring up the debug menu, and remembered I had set "Debug in Safari" on.
I turned this off, and some messages were printed to the output message, but not my console messages. However, one of the log messages said:
__DEV__ === false, development-level warning are OFF, performance optimizations are ON"
This was because I had previously bundled my project for testing on a real device with the command:
react-native bundle --minify
This bundled without "dev-mode" on. To allow development messages, include the --dev flag:
react-native bundle --dev
And console.log messages are back! If you aren't bundling for a real device, don't forget to re-point jsCodeLocation in AppDelegate.m to localhost (I did!).
Comments
Press [command + control + Z] in Xcode Simulator, choose Debug JS Remotely, then press [command + option + J] to open Chrome developer tools.
Comments
It's so simple to get logs in React-Native.
Use console.log and console.warn
console.log('character', parameter)
console.warn('character', parameter)
This log you can view in the browser console. If you want to check the device log or, say, a production APK log, you can use:
adb logcat
adb -d logcat
2 Comments
console.log and console.warn statements.There are two options to debug or get the output of your React Native application when using:
1. The emulator or a real device
For first using the emulator, use:
react-native log-android
or
react-native log-ios
to get the log output
2. On a real device, shake your device.
So the menu will come from where you select remote debug and it will open this screen in your browser. So you can see your log output in the console tab.
Comments
If you are on OS X and using an emulator, you can view your console.logs directly in Safari's web inspector.
Safari → Development → Simulator - [your simulator version here] → JSContext
Comments
Development Time Logging
For development time logging, you can use console.log(). One important thing, if you want to disable logging in production mode, then in Root Js file of app, just assign blank function like this - console.log = {} It will disable whole log publishing throughout app altogether, which actually required in production mode as console.log consumes time.
Run Time Logging
In production mode, it is also required to see logs when real users are using your app in real time. This helps in understanding bugs, usage and unwanted cases. There are many 3rd party paid tools available in the market for this. One of them which I've used is by Logentries
The good thing is that Logentries has got React Native Module as well. So, it will take very less time for you to enable Run time logging with your mobile app.
Comments
You use the same thing that is used for regular web. The console command also works in this case. For example, you can use console.log(), console.warn(),
console.clear() etc.
You can use Chrome Developer to use the console command when you're logging while you are running your React Native app.
Comments
The react-native-xlog module, that can help you, is WeChat's Xlog for React Native. That can output in the Xcode console and log file, and the Product log files can help you debug.
Xlog.verbose('tag', 'log');
Xlog.debug('tag', 'log');
Xlog.info('tag', 'log');
Xlog.warn('tag', 'log');
Xlog.error('tag', 'log');
Xlog.fatal('tag', 'log');
Comments
Use the React Native debugger for logging and Redux store - https://github.com/jhen0409/react-native-debugger
Just download it and run as software. Then enable Debug mode from the simulator.
It supports other debugging features, just like element in Google Chrome developer tools, which helps to see the styling provided to any component.
Last complete support for Redux development tools.
2 Comments
If you are using VSCode and run your emulator with VSCode React Native Tools, you can see console.* statements in the output tab. Make sure to select the correct subtab in the dropdown within the output tab. Mine currently is named LogCat - emulator-5554.
Comments
Something that just came out about a month ago is "Create React Native App," an awesome boilerplate that allows you (with minimal effort) to show what your app looks like live on your mobile device (ANY with a camera) using the Expo app. It not only has live updates, but it will allow you to see the console logs in your terminal just like when developing for the web, rather than having to use the browser like we did with React Native before.
You would, of course, have to make a new project with that boilerplate... but if you need to migrate your files over, that shouldn't be a problem. Give it a shot.
Edit: Actually it doesn't even require a camera. I said that for scanning a QR code, but you can also type out something to sync it up with your server, not just a QR code.
Comments
Every developer is facing this issue of debugging with React Native, and even I faced it too. I refer to this and the solution is sufficient for me at the initial level. It covers a few ways that help us to try and use whatever is comfortable with us.
- Debugging with console.log
- Debugging code (logic) with Nuclide
- Debugging code (logic) with Chrome
- Use Xcode to debug GUI
https://codeburst.io/react-native-debugging-tools-3a24e4e40e4
1 Comment
You can also use Reactotron. It will give you a lot more functionality than just logging.
1 Comment
You can use the remote js debugly option from your device or you can simply use react-native log-android and react-native log-ios for iOS.
1 Comment
console.log() is the easy way to debug your code, but it needs to be used with the arrow function or bind() while displaying any state. You may find Stack Overflow question How can I print state in the console with React Native? useful.
Comments
There are normally two scenarios where we need debugging.
When we are facing issues related to data and we want to check our data and debugging related to data. In that case,
console.log('data::', data)and debug JavaScript remotely is the best option.
Another case is the UI and styles related issues where we need to check the styling of the component. In that case, react-dev-tools is the best option.
Comments
You can do this by two methods
by using warn
console.warn("something " + this.state.Some_Sates_of_variables);By using Alert. This is not good every time. If it reaches an alert then each time a popup will be opened, so if doing looping it means it is not preferable to use this.
Import the {Alert} from 'react-native' // Use this alert Alert.alert("something " +this.state.Some_Sates_of_variables);
Comments
Users with Windows and Android Studio:
You're going to find it under Logcat in Android Studio. There are a lot of logging messages that show up here, so it may be easier for you to create a filter for "ReactNativeJS" which will only show your console.log messages that are created inside your React Native application.


