17 #include <android/log.h>
23 #if !defined(SPDLOG_ANDROID_RETRIES)
24 #define SPDLOG_ANDROID_RETRIES 2
33 template<
typename Mutex>
37 explicit android_sink(std::string tag =
"spdlog",
bool use_raw_msg =
false)
38 : tag_(
std::move(tag))
39 , use_raw_msg_(use_raw_msg)
46 const android_LogPriority priority = convert_to_android_(msg.
level);
57 const char *msg_output = formatted.
data();
60 int ret = __android_log_write(priority, tag_.c_str(), msg_output);
65 ret = __android_log_write(priority, tag_.c_str(), msg_output);
71 throw spdlog_ex(
"__android_log_write() failed", ret);
83 return ANDROID_LOG_VERBOSE;
85 return ANDROID_LOG_DEBUG;
87 return ANDROID_LOG_INFO;
89 return ANDROID_LOG_WARN;
91 return ANDROID_LOG_ERROR;
93 return ANDROID_LOG_FATAL;
95 return ANDROID_LOG_DEFAULT;
109 template<
typename Factory = default_factory>
110 inline std::shared_ptr<logger>
android_logger_mt(
const std::string &logger_name,
const std::string &tag =
"spdlog")
112 return Factory::template create<sinks::android_sink_mt>(logger_name, tag);
115 template<
typename Factory = default_factory>
116 inline std::shared_ptr<logger>
android_logger_st(
const std::string &logger_name,
const std::string &tag =
"spdlog")
118 return Factory::template create<sinks::android_sink_st>(logger_name, tag);