Debugging Native Code · React Native
If you are writing a Native Module and want to add custom logs to your module for debugging purposes, you can use the following method:
Android (Java/Kotlin)
In your native module, use the Log class to add logs that can be viewed in Logcat:
java
import android.util.Log;
private void log(String message) {
Log.d("YourModuleName", message);
}
To view these logs in Logcat, use this command, replacing YourModuleName with your custom tag:
shell
adb logcat "*:S" ReactNative:V ReactNativeJS:V YourModuleName:D
iOS (Objective-C/Swift)
In your native module, use NSLog for custom logs:
objective-c
NSLog(@"YourModuleName: %@", message);
Or, in Swift:
swift
print("YourModuleName: \(message)")
These logs will appear in the Xcode console when running the app.