Skip to content

Commit

Permalink
Merge pull request #570 from jiuqiant/patch-1
Browse files Browse the repository at this point in the history
Connect glog to Andorid logging API
  • Loading branch information
sergiud authored Sep 29, 2020
2 parents fcc9da2 + 64650ef commit fa0d50f
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion src/logging.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1525,6 +1525,23 @@ ostream& LogMessage::stream() {
return data_->stream_;
}

namespace {
#if defined(__ANDROID__)
int AndroidLogLevel(const int severity) {
switch (severity) {
case 3:
return ANDROID_LOG_FATAL;
case 2:
return ANDROID_LOG_ERROR;
case 1:
return ANDROID_LOG_WARN;
default:
return ANDROID_LOG_INFO;
}
}
#endif // defined(__ANDROID__)
} // namespace

// Flush buffered message, called by the destructor, or any other function
// that needs to synchronize the log.
void LogMessage::Flush() {
Expand Down Expand Up @@ -1559,7 +1576,13 @@ void LogMessage::Flush() {
++num_messages_[static_cast<int>(data_->severity_)];
}
LogDestination::WaitForSinks(data_);


#if defined(__ANDROID__)
const int level = AndroidLogLevel((int)data_->severity_);
const std::string text = std::string(data_->message_text_);
__android_log_write(level, "native", text.substr(0,data_->num_chars_to_log_).c_str());
#endif // !defined(__ANDROID__)

if (append_newline) {
// Fix the ostrstream back how it was before we screwed with it.
// It's 99.44% certain that we don't need to worry about doing this.
Expand Down

0 comments on commit fa0d50f

Please sign in to comment.