pg238
pg238

Reputation: 1155

how do I set logging levels on Android, for react native?

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?

Upvotes: 8

Views: 3534

Answers (3)

Nathan Dullea
Nathan Dullea

Reputation: 353

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.

Upvotes: 1

aMarCruz
aMarCruz

Reputation: 2852

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.

Upvotes: 1

Vincent D'amour
Vincent D'amour

Reputation: 3903

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.

Upvotes: 0

Related Questions