Merge "Base: Add INTERNAL_FATAL to logging severity"
This commit is contained in:
commit
88b5af68bd
3 changed files with 40 additions and 12 deletions
|
|
@ -41,6 +41,7 @@ enum LogSeverity {
|
||||||
INFO,
|
INFO,
|
||||||
WARNING,
|
WARNING,
|
||||||
ERROR,
|
ERROR,
|
||||||
|
FATAL_WITHOUT_ABORT,
|
||||||
FATAL,
|
FATAL,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -188,14 +188,18 @@ static const char* ProgramInvocationName() {
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
void KernelLogger(android::base::LogId, android::base::LogSeverity severity,
|
void KernelLogger(android::base::LogId, android::base::LogSeverity severity,
|
||||||
const char* tag, const char*, unsigned int, const char* msg) {
|
const char* tag, const char*, unsigned int, const char* msg) {
|
||||||
|
// clang-format off
|
||||||
static constexpr int kLogSeverityToKernelLogLevel[] = {
|
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
|
||||||
[android::base::DEBUG] = 7, // KERN_DEBUG
|
// level)
|
||||||
[android::base::INFO] = 6, // KERN_INFO
|
[android::base::DEBUG] = 7, // KERN_DEBUG
|
||||||
[android::base::WARNING] = 4, // KERN_WARNING
|
[android::base::INFO] = 6, // KERN_INFO
|
||||||
[android::base::ERROR] = 3, // KERN_ERROR
|
[android::base::WARNING] = 4, // KERN_WARNING
|
||||||
[android::base::FATAL] = 2, // KERN_CRIT
|
[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,
|
static_assert(arraysize(kLogSeverityToKernelLogLevel) == android::base::FATAL + 1,
|
||||||
"Mismatch in size of kLogSeverityToKernelLogLevel and values in LogSeverity");
|
"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];
|
char timestamp[32];
|
||||||
strftime(timestamp, sizeof(timestamp), "%m-%d %H:%M:%S", &now);
|
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,
|
static_assert(arraysize(log_characters) - 1 == FATAL + 1,
|
||||||
"Mismatch in size of log_characters and values in LogSeverity");
|
"Mismatch in size of log_characters and values in LogSeverity");
|
||||||
char severity_char = log_characters[severity];
|
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* file, unsigned int line,
|
||||||
const char* message) {
|
const char* message) {
|
||||||
static constexpr android_LogPriority kLogSeverityToAndroidLogPriority[] = {
|
static constexpr android_LogPriority kLogSeverityToAndroidLogPriority[] = {
|
||||||
ANDROID_LOG_VERBOSE, ANDROID_LOG_DEBUG, ANDROID_LOG_INFO,
|
ANDROID_LOG_VERBOSE, ANDROID_LOG_DEBUG, ANDROID_LOG_INFO,
|
||||||
ANDROID_LOG_WARN, ANDROID_LOG_ERROR, ANDROID_LOG_FATAL,
|
ANDROID_LOG_WARN, ANDROID_LOG_ERROR, ANDROID_LOG_FATAL,
|
||||||
|
ANDROID_LOG_FATAL,
|
||||||
};
|
};
|
||||||
static_assert(arraysize(kLogSeverityToAndroidLogPriority) == FATAL + 1,
|
static_assert(arraysize(kLogSeverityToAndroidLogPriority) == FATAL + 1,
|
||||||
"Mismatch in size of kLogSeverityToAndroidLogPriority and values in LogSeverity");
|
"Mismatch in size of kLogSeverityToAndroidLogPriority and values in LogSeverity");
|
||||||
|
|
@ -325,12 +330,12 @@ void InitLogging(char* argv[]) {
|
||||||
gMinimumLogSeverity = ERROR;
|
gMinimumLogSeverity = ERROR;
|
||||||
continue;
|
continue;
|
||||||
case 'f':
|
case 'f':
|
||||||
gMinimumLogSeverity = FATAL;
|
gMinimumLogSeverity = FATAL_WITHOUT_ABORT;
|
||||||
continue;
|
continue;
|
||||||
// liblog will even suppress FATAL if you say 's' for silent, but that's
|
// liblog will even suppress FATAL if you say 's' for silent, but that's
|
||||||
// crazy!
|
// crazy!
|
||||||
case 's':
|
case 's':
|
||||||
gMinimumLogSeverity = FATAL;
|
gMinimumLogSeverity = FATAL_WITHOUT_ABORT;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -122,7 +122,9 @@ TEST(logging, CHECK) {
|
||||||
|
|
||||||
static std::string make_log_pattern(android::base::LogSeverity severity,
|
static std::string make_log_pattern(android::base::LogSeverity severity,
|
||||||
const char* message) {
|
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];
|
char log_char = log_characters[severity];
|
||||||
std::string holder(__FILE__);
|
std::string holder(__FILE__);
|
||||||
return android::base::StringPrintf(
|
return android::base::StringPrintf(
|
||||||
|
|
@ -164,6 +166,14 @@ TEST(logging, LOG_FATAL) {
|
||||||
ASSERT_DEATH({SuppressAbortUI(); LOG(FATAL) << "foobar";}, "foobar");
|
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) {
|
TEST(logging, LOG_ERROR_disabled) {
|
||||||
CHECK_LOG_DISABLED(ERROR);
|
CHECK_LOG_DISABLED(ERROR);
|
||||||
}
|
}
|
||||||
|
|
@ -260,6 +270,18 @@ TEST(logging, LOG_does_not_have_dangling_if) {
|
||||||
PLOG(severity) << "foobar"; \
|
PLOG(severity) << "foobar"; \
|
||||||
CheckMessage(cap2, android::base::severity, "foobar: No such file or directory"); \
|
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) {
|
TEST(logging, PLOG_ERROR_disabled) {
|
||||||
CHECK_PLOG_DISABLED(ERROR);
|
CHECK_PLOG_DISABLED(ERROR);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue