How to do logging in React Native?

前端 未结 30 3062
不思量自难忘°
不思量自难忘° 2020-11-30 17:08

How can I log a variable in React Native, like using console.log when developing for web?

相关标签:
30条回答
  • 2020-11-30 17:25

    You can use Reactotron also, it will give you lot more functionality than just logging. https://github.com/infinitered/reactotron

    0 讨论(0)
  • 2020-11-30 17:29

    react-native-xlog module that can help you,is WeChat's Xlog for react-native. That can output in Xcode console and log file, 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');
    
    0 讨论(0)
  • 2020-11-30 17:29

    There are several ways to achieve this, I am listing them and including cons in using them also. You can use:

    1. console.log and view logging statements on, without opting out for remote debugging option from dev tools, Android Studio and Xcode. or you can opt out for remote debugging option and view logging on chrome dev tools or vscode or any other editor that supports debugging, you have to be cautious as this will slow down the process as a whole.
    2. You can use console.warn but then your mobile screen would be flooded with those weird yellow boxes which might or might not be feasible according to your situation.
    3. Most effective method that I came across is to use a third party tool, Reactotron. A simple and easy to configure tool that enables you to see each logging statement of different levels (error, debug, warn, etc.). It provides you with the GUI tool that shows all the logging of your app without slowing down the performance.
    0 讨论(0)
  • 2020-11-30 17:30
    1. Put console.log("My log text") in your code
    2. go to your command Line tools
    3. position oneself in its development folder

    In Android:

    • write this command : React-native log-android

    In IOS:

    • write this command : React-native log-ios
    0 讨论(0)
  • 2020-11-30 17:30

    Where you want to log data use

    console.log("data")

    And to print this log in terminal use command for android

    npx react-native log-android

    and for iOS

    npx react-native log-ios

    0 讨论(0)
  • 2020-11-30 17:34

    If you are on osx and using an emulator, you can view your console.logs directly in safari web inspector.

    Safari => Development => Simulator - [your simulator version here] => JSContext

    0 讨论(0)
提交回复
热议问题