React Native, Android Log.

React Native CLI now ships with a command for showing JavaScript logs:

npx react-native log-android

The cool thing is, if you use Log.i("ReactNative", "My log here"); (make sure to import it at the top of your Java file with import android.util.Log; first), you'll see it show up in the terminal. The magic part is the "ReactNative" filter for the first part of the Log.i method call.


If you put Log.ds in your native code, you can access the logs with Android Device Monitor in android studio, or with this command on the terminal: adb -d logcat <your package name>:<log level> *:S

Make sure USB debugging is enabled in your phone.


adb logcat -s can be used to print logs whose tags are listed in its tag list.

In the case of your question, the tag is "Notification", so you would view this with the command:

adb logcat -s Notification:V

For React Native development you will likely want the "ReactNative" and "ReactNativeJS" tags to get ReactNative and Javascript messages... so the appropriate command is:

adb logcat -s ReactNative:V,ReactNativeBleManager:V

To add the logs for any other module, look in the Java code to see what tag it is using, and add that to the list.

For example the bluetooth module "react-native-ble-manager" logs as Log.d("ReactNativeBleManager", "The log message"), so to include those messages change your command to:

adb logcat -s ReactNative:V,ReactNativeJS:V,ReactNativeBleManager:V

See the docs here: https://developer.android.com/studio/command-line/logcat.html for further information.


You can use https://www.npmjs.com/package/react-native-android-log

Example:

import Log from 'react-native-android-log'

// Set the default priority level (optional)
Log.setLevel(__DEV__ ? Log.VERBOSE : Log.WARN)

...
Log.v('Verbose message')    // no output in release builds
Log.w('Debugging')

// debugging message with amother tag:
Log.d('Proc2', 'warning')

You can see the output in the console through adb logcat -s App:V Proc2:V or in the OUTPUT panel of VS Code.