diff options
Diffstat (limited to 'base')
-rw-r--r-- | base/include/android-base/logging.h | 1 | ||||
-rw-r--r-- | base/logging.cpp | 27 | ||||
-rw-r--r-- | base/logging_test.cpp | 24 |
3 files changed, 40 insertions, 12 deletions
diff --git a/base/include/android-base/logging.h b/base/include/android-base/logging.h index 721ecceca..c626fc353 100644 --- a/base/include/android-base/logging.h +++ b/base/include/android-base/logging.h @@ -41,6 +41,7 @@ enum LogSeverity { INFO, WARNING, ERROR, + FATAL_WITHOUT_ABORT, FATAL, }; diff --git a/base/logging.cpp b/base/logging.cpp index 1f47a9fa3..86d3b4d26 100644 --- a/base/logging.cpp +++ b/base/logging.cpp @@ -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::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] = 2, // KERN_CRIT + [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"); @@ -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]; @@ -252,8 +256,9 @@ void LogdLogger::operator()(LogId id, LogSeverity severity, const char* tag, const char* file, unsigned int line, const char* message) { 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_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"); @@ -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; } } diff --git a/base/logging_test.cpp b/base/logging_test.cpp index 6a321fce5..3fde302a3 100644 --- a/base/logging_test.cpp +++ b/base/logging_test.cpp @@ -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( @@ -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); } @@ -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); } |