Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can logcat be used to log NDK code in Android? Or what are logging options from NDK?

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.

like image 546
22332112 Avatar asked Aug 05 '14 22:08

22332112


People also ask

What is the use of Logcat in Android?

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.

Which of the following method in Android is used to log error messages?

Answer - B) Log. d() is used to log debug messages.


1 Answers

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?

like image 141
AnkitSomani Avatar answered Sep 20 '22 11:09

AnkitSomani