|
73 | 73 | # include "stacktrace.h"
|
74 | 74 | #endif
|
75 | 75 |
|
| 76 | +#ifdef __ANDROID__ |
| 77 | +#include <android/log.h> |
| 78 | +#endif |
| 79 | + |
76 | 80 | using std::string;
|
77 | 81 | using std::vector;
|
78 | 82 | using std::setw;
|
@@ -1485,6 +1489,23 @@ ostream& LogMessage::stream() {
|
1485 | 1489 | return data_->stream_;
|
1486 | 1490 | }
|
1487 | 1491 |
|
| 1492 | +namespace { |
| 1493 | +#if defined(__ANDROID__) |
| 1494 | +int AndroidLogLevel(const int severity) { |
| 1495 | + switch (severity) { |
| 1496 | + case 3: |
| 1497 | + return ANDROID_LOG_FATAL; |
| 1498 | + case 2: |
| 1499 | + return ANDROID_LOG_ERROR; |
| 1500 | + case 1: |
| 1501 | + return ANDROID_LOG_WARN; |
| 1502 | + default: |
| 1503 | + return ANDROID_LOG_INFO; |
| 1504 | + } |
| 1505 | +} |
| 1506 | +#endif // defined(__ANDROID__) |
| 1507 | +} // namespace |
| 1508 | + |
1488 | 1509 | // Flush buffered message, called by the destructor, or any other function
|
1489 | 1510 | // that needs to synchronize the log.
|
1490 | 1511 | void LogMessage::Flush() {
|
@@ -1518,7 +1539,13 @@ void LogMessage::Flush() {
|
1518 | 1539 | ++num_messages_[static_cast<int>(data_->severity_)];
|
1519 | 1540 | }
|
1520 | 1541 | LogDestination::WaitForSinks(data_);
|
1521 |
| - |
| 1542 | + |
| 1543 | +#if defined(__ANDROID__) |
| 1544 | + const int level = AndroidLogLevel((int)data_->severity_); |
| 1545 | + const std::string text = std::string(data_->message_text_); |
| 1546 | + __android_log_write(level, "native", text.substr(0,data_->num_chars_to_log_).c_str()); |
| 1547 | +#endif // !defined(__ANDROID__) |
| 1548 | + |
1522 | 1549 | if (append_newline) {
|
1523 | 1550 | // Fix the ostrstream back how it was before we screwed with it.
|
1524 | 1551 | // It's 99.44% certain that we don't need to worry about doing this.
|
|
0 commit comments