8

I was going through react native code and found the following code in one of the files:

#define RCTLog(...) _RCTLog(RCTLogLevelInfo, __VA_ARGS__)
#define RCTLogTrace(...) _RCTLog(RCTLogLevelTrace, __VA_ARGS__)
#define RCTLogInfo(...) _RCTLog(RCTLogLevelInfo, __VA_ARGS__)
#define RCTLogWarn(...) _RCTLog(RCTLogLevelWarning, __VA_ARGS__)
#define RCTLogError(...) _RCTLog(RCTLogLevelError, __VA_ARGS__)

I was wondering if there is something similar (in react native) for Android as well. I tried fishing through the react native code, but could not find any way to do it. I was wondering if anyone had to do it for Android.

Can someone please help me with this?

3 Answers 3

1

Maybe is too late for this, but you can use react-native-android-log (I'm the author).

Example:

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

// Set the default level (optional)
Log.setLevel(__DEV__ ? Log.VERBOSE : Log.WARN)
...
Log.v('Verbose message')    // no output in release builds
Log.w('Debugging')

...and see the output in the console through adb:

$ adb logcat -s App:V

...or in the "OUTPUT" panel of VS Code.

Please take a look at the README of the package, there you will find how to configure and use it.

Sign up to request clarification or add additional context in comments.

Comments

1

I was using some external libraries/APIs which I was unable to debug my problems with the standard logging.

Putting

window.LOG_LEVEL = 'DEBUG'

at the top of App.js printed the external logs, allowing me to debug my problem. I think there are other log levels you can pass to the window as well.

Comments

0

React-native is using Yoga under the hood to display their log message to the screen. I was not able to find any library doing the same for android app. There is plenty of library showing message on screen that you can use to display your log message. Inside react-native, the log component is built from the objective-c code, so you cannot access it from java. I tried in the past few days to find something similar but I was not able. There is also plenty of tool to help you log all kind of info, but the log is always shown in the console.

4 Comments

We don't want answer for JS but for JAVA (Android) - but thanks.
What do you want exactly? If you want to log data while developing your app into a console, you can use the JS console, the android one, or the iOS one. You can also see your logs in the Android Studio console, xCode console, in your terminal or in most IDE console. Or were you talking about report logs, when the app crash on an unknown user device for example? If you want to write log into the console in JAVA, here's how to do it: developer.android.com/studio/debug/am-logcat.html With a little bit more detail, I will probably be able to be more helpful.
_RCTLog(RCTLogLevelWarning allow us to add native logs which are diplay in RN layer like with console.warn('message'). We want to found the same way but for Android
I edited my answer base the research I did this week.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.