Sadik Armagan | 8f397a1 | 2022-06-17 15:38:22 +0100 | [diff] [blame] | 1 | diff --git a/logging.cpp b/logging.cpp |
| 2 | index 4942e2f..1ff0996 100644 |
| 3 | --- a/logging.cpp |
| 4 | +++ b/logging.cpp |
| 5 | @@ -209,9 +209,9 @@ static std::recursive_mutex& TagLock() { |
| 6 | static std::string* gDefaultTag; |
| 7 | |
| 8 | void SetDefaultTag(const std::string& tag) { |
| 9 | - if (__builtin_available(android 30, *)) { |
| 10 | - __android_log_set_default_tag(tag.c_str()); |
| 11 | - } else { |
| 12 | +// if (__builtin_available(android 30, *)) { |
| 13 | +// __android_log_set_default_tag(tag.c_str()); |
| 14 | +// } else { |
| 15 | std::lock_guard<std::recursive_mutex> lock(TagLock()); |
| 16 | if (gDefaultTag != nullptr) { |
| 17 | delete gDefaultTag; |
| 18 | @@ -220,7 +220,7 @@ void SetDefaultTag(const std::string& tag) { |
| 19 | if (!tag.empty()) { |
| 20 | gDefaultTag = new std::string(tag); |
| 21 | } |
| 22 | - } |
| 23 | +// } |
| 24 | } |
| 25 | |
| 26 | static bool gInitialized = false; |
| 27 | @@ -314,13 +314,13 @@ static void LogdLogChunk(LogId id, LogSeverity severity, const char* tag, const |
| 28 | int32_t lg_id = LogIdTolog_id_t(id); |
| 29 | int32_t priority = LogSeverityToPriority(severity); |
| 30 | |
| 31 | - if (__builtin_available(android 30, *)) { |
| 32 | - __android_log_message log_message = {sizeof(__android_log_message), lg_id, priority, tag, |
| 33 | - static_cast<const char*>(nullptr), 0, message}; |
| 34 | - __android_log_logd_logger(&log_message); |
| 35 | - } else { |
| 36 | +// if (__builtin_available(android 30, *)) { |
| 37 | +// __android_log_message log_message = {sizeof(__android_log_message), lg_id, priority, tag, |
| 38 | +// static_cast<const char*>(nullptr), 0, message}; |
| 39 | +// __android_log_logd_logger(&log_message); |
| 40 | +// } else { |
| 41 | __android_log_buf_print(lg_id, priority, tag, "%s", message); |
| 42 | - } |
| 43 | +// } |
| 44 | } |
| 45 | |
| 46 | LogdLogger::LogdLogger(LogId default_log_id) : default_log_id_(default_log_id) {} |
| 47 | @@ -396,15 +396,15 @@ LogFunction SetLogger(LogFunction&& logger) { |
| 48 | LogFunction old_logger = std::move(Logger()); |
| 49 | Logger() = std::move(logger); |
| 50 | |
| 51 | - if (__builtin_available(android 30, *)) { |
| 52 | - __android_log_set_logger([](const struct __android_log_message* log_message) { |
| 53 | - auto log_id = log_id_tToLogId(log_message->buffer_id); |
| 54 | - auto severity = PriorityToLogSeverity(log_message->priority); |
| 55 | - |
| 56 | - Logger()(log_id, severity, log_message->tag, log_message->file, log_message->line, |
| 57 | - log_message->message); |
| 58 | - }); |
| 59 | - } |
| 60 | +// if (__builtin_available(android 30, *)) { |
| 61 | +// __android_log_set_logger([](const struct __android_log_message* log_message) { |
| 62 | +// auto log_id = log_id_tToLogId(log_message->buffer_id); |
| 63 | +// auto severity = PriorityToLogSeverity(log_message->priority); |
| 64 | +// |
| 65 | +// Logger()(log_id, severity, log_message->tag, log_message->file, log_message->line, |
| 66 | +// log_message->message); |
| 67 | +// }); |
| 68 | +// } |
| 69 | return old_logger; |
| 70 | } |
| 71 | |
| 72 | @@ -412,9 +412,9 @@ AbortFunction SetAborter(AbortFunction&& aborter) { |
| 73 | AbortFunction old_aborter = std::move(Aborter()); |
| 74 | Aborter() = std::move(aborter); |
| 75 | |
| 76 | - if (__builtin_available(android 30, *)) { |
| 77 | - __android_log_set_aborter([](const char* abort_message) { Aborter()(abort_message); }); |
| 78 | - } |
| 79 | +// if (__builtin_available(android 30, *)) { |
| 80 | +// __android_log_set_aborter([](const char* abort_message) { Aborter()(abort_message); }); |
| 81 | +// } |
| 82 | return old_aborter; |
| 83 | } |
| 84 | |
| 85 | @@ -500,11 +500,11 @@ LogMessage::~LogMessage() { |
| 86 | |
| 87 | // Abort if necessary. |
| 88 | if (data_->GetSeverity() == FATAL) { |
| 89 | - if (__builtin_available(android 30, *)) { |
| 90 | - __android_log_call_aborter(msg.c_str()); |
| 91 | - } else { |
| 92 | +// if (__builtin_available(android 30, *)) { |
| 93 | +// __android_log_call_aborter(msg.c_str()); |
| 94 | +// } else { |
| 95 | Aborter()(msg.c_str()); |
| 96 | - } |
| 97 | +// } |
| 98 | } |
| 99 | } |
| 100 | |
| 101 | @@ -515,11 +515,11 @@ std::ostream& LogMessage::stream() { |
| 102 | void LogMessage::LogLine(const char* file, unsigned int line, LogSeverity severity, const char* tag, |
| 103 | const char* message) { |
| 104 | int32_t priority = LogSeverityToPriority(severity); |
| 105 | - if (__builtin_available(android 30, *)) { |
| 106 | - __android_log_message log_message = { |
| 107 | - sizeof(__android_log_message), LOG_ID_DEFAULT, priority, tag, file, line, message}; |
| 108 | - __android_log_write_log_message(&log_message); |
| 109 | - } else { |
| 110 | +// if (__builtin_available(android 30, *)) { |
| 111 | +// __android_log_message log_message = { |
| 112 | +// sizeof(__android_log_message), LOG_ID_DEFAULT, priority, tag, file, line, message}; |
| 113 | +// __android_log_write_log_message(&log_message); |
| 114 | +// } else { |
| 115 | if (tag == nullptr) { |
| 116 | std::lock_guard<std::recursive_mutex> lock(TagLock()); |
| 117 | if (gDefaultTag == nullptr) { |
| 118 | @@ -530,38 +530,38 @@ void LogMessage::LogLine(const char* file, unsigned int line, LogSeverity severi |
| 119 | } else { |
| 120 | Logger()(DEFAULT, severity, tag, file, line, message); |
| 121 | } |
| 122 | - } |
| 123 | +// } |
| 124 | } |
| 125 | |
| 126 | LogSeverity GetMinimumLogSeverity() { |
| 127 | - if (__builtin_available(android 30, *)) { |
| 128 | - return PriorityToLogSeverity(__android_log_get_minimum_priority()); |
| 129 | - } else { |
| 130 | +// if (__builtin_available(android 30, *)) { |
| 131 | +// return PriorityToLogSeverity(__android_log_get_minimum_priority()); |
| 132 | +// } else { |
| 133 | return gMinimumLogSeverity; |
| 134 | - } |
| 135 | +// } |
| 136 | } |
| 137 | |
| 138 | bool ShouldLog(LogSeverity severity, const char* tag) { |
| 139 | // Even though we're not using the R liblog functions in this function, if we're running on Q, |
| 140 | // we need to fall back to using gMinimumLogSeverity, since __android_log_is_loggable() will not |
| 141 | // take into consideration the value from SetMinimumLogSeverity(). |
| 142 | - if (__builtin_available(android 30, *)) { |
| 143 | - int32_t priority = LogSeverityToPriority(severity); |
| 144 | - return __android_log_is_loggable(priority, tag, ANDROID_LOG_INFO); |
| 145 | - } else { |
| 146 | +// if (__builtin_available(android 30, *)) { |
| 147 | +// int32_t priority = LogSeverityToPriority(severity); |
| 148 | +// return __android_log_is_loggable(priority, tag, ANDROID_LOG_INFO); |
| 149 | +// } else { |
| 150 | return severity >= gMinimumLogSeverity; |
| 151 | - } |
| 152 | +// } |
| 153 | } |
| 154 | |
| 155 | LogSeverity SetMinimumLogSeverity(LogSeverity new_severity) { |
| 156 | - if (__builtin_available(android 30, *)) { |
| 157 | - int32_t priority = LogSeverityToPriority(new_severity); |
| 158 | - return PriorityToLogSeverity(__android_log_set_minimum_priority(priority)); |
| 159 | - } else { |
| 160 | +// if (__builtin_available(android 30, *)) { |
| 161 | +// int32_t priority = LogSeverityToPriority(new_severity); |
| 162 | +// return PriorityToLogSeverity(__android_log_set_minimum_priority(priority)); |
| 163 | +// } else { |
| 164 | LogSeverity old_severity = gMinimumLogSeverity; |
| 165 | gMinimumLogSeverity = new_severity; |
| 166 | return old_severity; |
| 167 | - } |
| 168 | +// } |
| 169 | } |
| 170 | |
| 171 | ScopedLogSeverity::ScopedLogSeverity(LogSeverity new_severity) { |