In Android-ndk, we could use \"__android_log_write\", \"__android_log_print\", ... etc to output messages to the \"LogCat\" window. How about if I use \"std::cout\" to outpu
Another option:
#include
class MyStream
{
private:
std::stringstream m_ss;
int m_logLevel;
public:
MyStream(int Xi_logLevel)
{
m_logLevel = Xi_logLevel;
};
~MyStream()
{
__android_log_print(m_logLevel,LOG_TAG,"%s", m_ss.str().c_str());
}
template MyStream& operator<<(T const& Xi_val)
{
m_ss << Xi_val;
return *this;
}
};
#define MY_LOG(LOG_LEVEL) MyStream(ANDROID_LOG_##LOG_LEVEL) << __FUNCTION__ << ":" << __LINE__ << " : "
PROS:
(1) The messages are printed immediately.
CONS:
(1) You must to change your code (std::cout -> MY_LOG(X)).
(2) Each a single print produces an object and destroys it.
(*** This answer base on this answer)