8 #if defined(__ANDROID__) 14 #include <android/log.h> 18 #if !defined(SPDLOG_ANDROID_RETRIES) 19 #define SPDLOG_ANDROID_RETRIES 2 31 class android_sink :
public sink
34 explicit android_sink(
const std::string& tag =
"spdlog",
bool use_raw_msg =
false): _tag(tag), _use_raw_msg(use_raw_msg) {}
36 void log(
const details::log_msg& msg)
override 38 const android_LogPriority priority = convert_to_android(msg.level);
39 const char *msg_output = (_use_raw_msg ? msg.raw.c_str() : msg.formatted.c_str());
42 int ret = __android_log_write(priority, _tag.c_str(), msg_output);
44 while ((ret == -11) && (retry_count < SPDLOG_ANDROID_RETRIES))
46 std::this_thread::sleep_for(std::chrono::milliseconds(5));
47 ret = __android_log_write(priority, _tag.c_str(), msg_output);
53 throw spdlog_ex(
"__android_log_write() failed", ret);
67 return ANDROID_LOG_VERBOSE;
69 return ANDROID_LOG_DEBUG;
71 return ANDROID_LOG_INFO;
73 return ANDROID_LOG_WARN;
75 return ANDROID_LOG_ERROR;
77 return ANDROID_LOG_FATAL;
79 return ANDROID_LOG_DEFAULT;
OStream< ChannelType > & flush(OStream< ChannelType > &os)