How to enable ALOGV verbose debug messages in Android Logcat ?

When developing Android applications, debugging is a crucial part of ensuring your code works as expected. One of the most powerful tools for debugging in Android is Logcat, which allows you to view and filter log messages generated by your app. Among the various log levels available, ALOGV (Verbose) is particularly useful for detailed debugging, as it provides the most granular level of log output. In this guide, we will walk you through the steps to enable ALOGV verbose debug messages in Android Logcat, helping you gain deeper insights into your app’s behavior.

By default, ALOGV “VERBOSE messages” are removed from the release builds of Android. So, if we want to make sure those messages are available in logcat, so we can debug the respective application / subsystem, then we need to enable this verbose messaging for per file basis.

So to enable “ALOGV” message, open the individual source file from which we want to have the debug messages enable and define “LOG_NDEBUG” as 0 at the top.

# define LOG_NDEBUG 0

This has been mentioned at platform/system/core/include/cutils/log.h file as,

/*
 * Normally we strip ALOGV (VERBOSE messages) from release builds.
 * You can modify this (for example with "#define LOG_NDEBUG 0"
 * at the top of your source file) to change that behavior.
 */
#ifndef LOG_NDEBUG
#ifdef NDEBUG
#define LOG_NDEBUG 1
#else
#define LOG_NDEBUG 0
#endif
#endif

So, if we want to enable ALOGV messages from frameworks/av/media/libmedia/mediaplayer.cpp ,

status_t MediaPlayer::setDataSource(int fd, int64_t offset, int64_t length)
{
    ALOGV("setDataSource(%d, %" PRId64 ", %" PRId64 ")", fd, offset, length);
}

then, open this file frameworks/av/media/libmedia/mediaplayer.cpp and uncomment the below line,

//#define LOG_NDEBUG 0

change to

#define LOG_NDEBUG 0

Leave a Comment