20 #include <android/log.h>
27 std::vector<std::string> SplitStringOnLineBreaks(
const std::string&
str) {
28 std::vector<std::string> strings;
31 const size_t length = str.length();
32 while (end_pos != std::string::npos && end_pos < length) {
33 const size_t start_pos = end_pos;
35 end_pos = str.find_first_of(
'\n', start_pos);
37 strings.push_back(str.substr(start_pos, end_pos - start_pos));
40 if (end_pos != std::string::npos)
48 AndroidLogEntryWriter() {}
49 virtual ~AndroidLogEntryWriter() {}
53 const std::string& message) {
54 android_LogPriority priority;
58 priority = ANDROID_LOG_INFO;
61 priority = ANDROID_LOG_WARN;
64 priority = ANDROID_LOG_ERROR;
67 priority = ANDROID_LOG_FATAL;
70 priority = ANDROID_LOG_FATAL;
75 const std::vector<std::string> lines = SplitStringOnLineBreaks(message);
76 for (
auto it = lines.begin(); it < lines.end(); ++it)
77 __android_log_write(priority,
"Ion", it->c_str());
88 return new AndroidLogEntryWriter();
Abstract class which can be overridden to integrate Ion logging with other logging systems...
virtual void Write(LogSeverity severity, const std::string &message)=0
const char * GetSeverityName(LogSeverity severity) const
Convenient way to map a severity-code to a printable represenation.
ION_API LogEntryWriter * CreateDefaultLogEntryWriter()
Instantiate a new LogEntryWriter of the default type for the current platform...