How would one write logs from inside Native code in Android (NDK)? What are the available options? For example, can logcat be used from inside of NDK to write logs? Or since its more upper level in android, it can not be accessible from NDK?
At the moment I am just aware of writing times from C code with:
millis = System.currentTimeMillis();
And with function that would write this time plus any messages to a custom log file.
Logcat is a command-line tool that dumps a log of system messages, including stack traces when the device throws an error and messages that you have written from your app with the Log class. This page is about the command-line logcat tool, but you can also view log messages from the Logcat window in Android Studio.
Answer - B) Log. d() is used to log debug messages.
You can use the Android logging
#include <android/log.h>
#define APPNAME "MyApp"
__android_log_print(ANDROID_LOG_VERBOSE, APPNAME, "My Log");
Also Make sure you also link against the logging library, in your Android.mk file:
LOCAL_LDLIBS := -llog
It has already been discussed at Any simple way to log in Android NDK code?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With