lang:android:log
NDK
stringstream et __android_log_print
Avec une adaptation pour les cas non Android.
#ifdef __ANDROID__ #include <android/log.h> #include <sstream> 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 <typename T> MyStream& operator<<(T&& Xi_val) { m_ss << std::forward<T>(Xi_val); return *this; } }; #define MY_LOG(LOG_LEVEL) MyStream(ANDROID_LOG_##LOG_LEVEL) #else #include <iostream> enum LogPriority { LOG_UNKNOWN = 0, LOG_DEFAULT, LOG_VERBOSE, LOG_DEBUG, LOG_INFO, LOG_WARN, LOG_ERROR, LOG_FATAL, LOG_SILENT }; #define MY_LOG(LOG_LEVEL) (LOG_##LOG_LEVEL <= LOG_INFO ? std::cout : std::cerr) #endif
Is "std::cout" usable in Android-ndk Archive du 15/01/2012 le 30/01/2023
lang/android/log.txt · Dernière modification : 2023/01/30 10:13 de root