Loading base/include/android-base/logging.h +1 −0 Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ enum LogSeverity { INFO, WARNING, ERROR, FATAL_WITHOUT_ABORT, FATAL, }; Loading base/logging.cpp +16 −11 Original line number Diff line number Diff line Loading @@ -188,14 +188,18 @@ static const char* ProgramInvocationName() { #if defined(__linux__) void KernelLogger(android::base::LogId, android::base::LogSeverity severity, const char* tag, const char*, unsigned int, const char* msg) { // clang-format off static constexpr int kLogSeverityToKernelLogLevel[] = { [android::base::VERBOSE] = 7, // KERN_DEBUG (there is no verbose kernel log level) [android::base::VERBOSE] = 7, // KERN_DEBUG (there is no verbose kernel log // level) [android::base::DEBUG] = 7, // KERN_DEBUG [android::base::INFO] = 6, // KERN_INFO [android::base::WARNING] = 4, // KERN_WARNING [android::base::ERROR] = 3, // KERN_ERROR [android::base::FATAL_WITHOUT_ABORT] = 2, // KERN_CRIT [android::base::FATAL] = 2, // KERN_CRIT }; // clang-format on static_assert(arraysize(kLogSeverityToKernelLogLevel) == android::base::FATAL + 1, "Mismatch in size of kLogSeverityToKernelLogLevel and values in LogSeverity"); Loading Loading @@ -235,7 +239,7 @@ void StderrLogger(LogId, LogSeverity severity, const char*, const char* file, char timestamp[32]; strftime(timestamp, sizeof(timestamp), "%m-%d %H:%M:%S", &now); static const char log_characters[] = "VDIWEF"; static const char log_characters[] = "VDIWEFF"; static_assert(arraysize(log_characters) - 1 == FATAL + 1, "Mismatch in size of log_characters and values in LogSeverity"); char severity_char = log_characters[severity]; Loading @@ -254,6 +258,7 @@ void LogdLogger::operator()(LogId id, LogSeverity severity, const char* tag, static constexpr android_LogPriority kLogSeverityToAndroidLogPriority[] = { ANDROID_LOG_VERBOSE, ANDROID_LOG_DEBUG, ANDROID_LOG_INFO, ANDROID_LOG_WARN, ANDROID_LOG_ERROR, ANDROID_LOG_FATAL, ANDROID_LOG_FATAL, }; static_assert(arraysize(kLogSeverityToAndroidLogPriority) == FATAL + 1, "Mismatch in size of kLogSeverityToAndroidLogPriority and values in LogSeverity"); Loading Loading @@ -325,12 +330,12 @@ void InitLogging(char* argv[]) { gMinimumLogSeverity = ERROR; continue; case 'f': gMinimumLogSeverity = FATAL; gMinimumLogSeverity = FATAL_WITHOUT_ABORT; continue; // liblog will even suppress FATAL if you say 's' for silent, but that's // crazy! case 's': gMinimumLogSeverity = FATAL; gMinimumLogSeverity = FATAL_WITHOUT_ABORT; continue; } } Loading base/logging_test.cpp +23 −1 Original line number Diff line number Diff line Loading @@ -122,7 +122,9 @@ TEST(logging, CHECK) { static std::string make_log_pattern(android::base::LogSeverity severity, const char* message) { static const char* log_characters = "VDIWEF"; static const char log_characters[] = "VDIWEFF"; static_assert(arraysize(log_characters) - 1 == android::base::FATAL + 1, "Mismatch in size of log_characters and values in LogSeverity"); char log_char = log_characters[severity]; std::string holder(__FILE__); return android::base::StringPrintf( Loading Loading @@ -164,6 +166,14 @@ TEST(logging, LOG_FATAL) { ASSERT_DEATH({SuppressAbortUI(); LOG(FATAL) << "foobar";}, "foobar"); } TEST(logging, LOG_FATAL_WITHOUT_ABORT_disabled) { CHECK_LOG_DISABLED(FATAL_WITHOUT_ABORT); } TEST(logging, LOG_FATAL_WITHOUT_ABORT_enabled) { CHECK_LOG_ENABLED(FATAL_WITHOUT_ABORT); } TEST(logging, LOG_ERROR_disabled) { CHECK_LOG_DISABLED(ERROR); } Loading Loading @@ -260,6 +270,18 @@ TEST(logging, LOG_does_not_have_dangling_if) { PLOG(severity) << "foobar"; \ CheckMessage(cap2, android::base::severity, "foobar: No such file or directory"); \ TEST(logging, PLOG_FATAL) { ASSERT_DEATH({SuppressAbortUI(); PLOG(FATAL) << "foobar";}, "foobar"); } TEST(logging, PLOG_FATAL_WITHOUT_ABORT_disabled) { CHECK_PLOG_DISABLED(FATAL_WITHOUT_ABORT); } TEST(logging, PLOG_FATAL_WITHOUT_ABORT_enabled) { CHECK_PLOG_ENABLED(FATAL_WITHOUT_ABORT); } TEST(logging, PLOG_ERROR_disabled) { CHECK_PLOG_DISABLED(ERROR); } Loading Loading
base/include/android-base/logging.h +1 −0 Original line number Diff line number Diff line Loading @@ -41,6 +41,7 @@ enum LogSeverity { INFO, WARNING, ERROR, FATAL_WITHOUT_ABORT, FATAL, }; Loading
base/logging.cpp +16 −11 Original line number Diff line number Diff line Loading @@ -188,14 +188,18 @@ static const char* ProgramInvocationName() { #if defined(__linux__) void KernelLogger(android::base::LogId, android::base::LogSeverity severity, const char* tag, const char*, unsigned int, const char* msg) { // clang-format off static constexpr int kLogSeverityToKernelLogLevel[] = { [android::base::VERBOSE] = 7, // KERN_DEBUG (there is no verbose kernel log level) [android::base::VERBOSE] = 7, // KERN_DEBUG (there is no verbose kernel log // level) [android::base::DEBUG] = 7, // KERN_DEBUG [android::base::INFO] = 6, // KERN_INFO [android::base::WARNING] = 4, // KERN_WARNING [android::base::ERROR] = 3, // KERN_ERROR [android::base::FATAL_WITHOUT_ABORT] = 2, // KERN_CRIT [android::base::FATAL] = 2, // KERN_CRIT }; // clang-format on static_assert(arraysize(kLogSeverityToKernelLogLevel) == android::base::FATAL + 1, "Mismatch in size of kLogSeverityToKernelLogLevel and values in LogSeverity"); Loading Loading @@ -235,7 +239,7 @@ void StderrLogger(LogId, LogSeverity severity, const char*, const char* file, char timestamp[32]; strftime(timestamp, sizeof(timestamp), "%m-%d %H:%M:%S", &now); static const char log_characters[] = "VDIWEF"; static const char log_characters[] = "VDIWEFF"; static_assert(arraysize(log_characters) - 1 == FATAL + 1, "Mismatch in size of log_characters and values in LogSeverity"); char severity_char = log_characters[severity]; Loading @@ -254,6 +258,7 @@ void LogdLogger::operator()(LogId id, LogSeverity severity, const char* tag, static constexpr android_LogPriority kLogSeverityToAndroidLogPriority[] = { ANDROID_LOG_VERBOSE, ANDROID_LOG_DEBUG, ANDROID_LOG_INFO, ANDROID_LOG_WARN, ANDROID_LOG_ERROR, ANDROID_LOG_FATAL, ANDROID_LOG_FATAL, }; static_assert(arraysize(kLogSeverityToAndroidLogPriority) == FATAL + 1, "Mismatch in size of kLogSeverityToAndroidLogPriority and values in LogSeverity"); Loading Loading @@ -325,12 +330,12 @@ void InitLogging(char* argv[]) { gMinimumLogSeverity = ERROR; continue; case 'f': gMinimumLogSeverity = FATAL; gMinimumLogSeverity = FATAL_WITHOUT_ABORT; continue; // liblog will even suppress FATAL if you say 's' for silent, but that's // crazy! case 's': gMinimumLogSeverity = FATAL; gMinimumLogSeverity = FATAL_WITHOUT_ABORT; continue; } } Loading
base/logging_test.cpp +23 −1 Original line number Diff line number Diff line Loading @@ -122,7 +122,9 @@ TEST(logging, CHECK) { static std::string make_log_pattern(android::base::LogSeverity severity, const char* message) { static const char* log_characters = "VDIWEF"; static const char log_characters[] = "VDIWEFF"; static_assert(arraysize(log_characters) - 1 == android::base::FATAL + 1, "Mismatch in size of log_characters and values in LogSeverity"); char log_char = log_characters[severity]; std::string holder(__FILE__); return android::base::StringPrintf( Loading Loading @@ -164,6 +166,14 @@ TEST(logging, LOG_FATAL) { ASSERT_DEATH({SuppressAbortUI(); LOG(FATAL) << "foobar";}, "foobar"); } TEST(logging, LOG_FATAL_WITHOUT_ABORT_disabled) { CHECK_LOG_DISABLED(FATAL_WITHOUT_ABORT); } TEST(logging, LOG_FATAL_WITHOUT_ABORT_enabled) { CHECK_LOG_ENABLED(FATAL_WITHOUT_ABORT); } TEST(logging, LOG_ERROR_disabled) { CHECK_LOG_DISABLED(ERROR); } Loading Loading @@ -260,6 +270,18 @@ TEST(logging, LOG_does_not_have_dangling_if) { PLOG(severity) << "foobar"; \ CheckMessage(cap2, android::base::severity, "foobar: No such file or directory"); \ TEST(logging, PLOG_FATAL) { ASSERT_DEATH({SuppressAbortUI(); PLOG(FATAL) << "foobar";}, "foobar"); } TEST(logging, PLOG_FATAL_WITHOUT_ABORT_disabled) { CHECK_PLOG_DISABLED(FATAL_WITHOUT_ABORT); } TEST(logging, PLOG_FATAL_WITHOUT_ABORT_enabled) { CHECK_PLOG_ENABLED(FATAL_WITHOUT_ABORT); } TEST(logging, PLOG_ERROR_disabled) { CHECK_PLOG_DISABLED(ERROR); } Loading