Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 497
user4122421 Avatar asked Aug 22 '16 17:08

user4122421


2 Answers

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.

like image 74
aMarCruz Avatar answered Sep 19 '22 15:09

aMarCruz


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.

like image 31
Nathan Dullea Avatar answered Sep 20 '22 15:09

Nathan Dullea