Migrate from LOG_X to kLogX. (flutter/engine#46107)

These should be entirely non-breaking, i.e. 1:1 and same backing `int`
value.

(See https://github.com/flutter/engine/pull/46052)
This commit is contained in:
Matan Lurey
2023-09-20 13:24:01 -07:00
committed by GitHub
parent 002e1a2047
commit 476b46954c
6 changed files with 27 additions and 25 deletions

View File

@@ -12,6 +12,7 @@
#include <limits>
#include "flutter/fml/build_config.h"
#include "flutter/fml/log_level.h"
#include "flutter/fml/logging.h"
#if defined(OS_FUCHSIA)
@@ -29,7 +30,7 @@ extern LogSettings g_log_settings;
void SetLogSettings(const LogSettings& settings) {
// Validate the new settings as we set them.
state::g_log_settings.min_log_level =
std::min(LOG_FATAL, settings.min_log_level);
std::min(kLogFatal, settings.min_log_level);
#if defined(OS_FUCHSIA)
// Syslog should accept all logs, since filtering by severity is done by fml.
fx_logger_t* logger = fx_log_get_logger();
@@ -45,7 +46,7 @@ LogSettings GetLogSettings() {
}
int GetMinLogLevel() {
return std::min(state::g_log_settings.min_log_level, LOG_FATAL);
return std::min(state::g_log_settings.min_log_level, kLogFatal);
}
ScopedSetLogSettings::ScopedSetLogSettings(const LogSettings& settings) {

View File

@@ -17,12 +17,12 @@ struct LogSettings {
// Anything at or above this level will be logged (if applicable).
// Anything below this level will be silently ignored.
//
// The log level defaults to 0 (LOG_INFO).
// The log level defaults to 0 (kLogInfo).
//
// Log messages for FML_VLOG(x) (from flutter/fml/logging.h) are logged
// at level -x, so setting the min log level to negative values enables
// verbose logging.
LogSeverity min_log_level = LOG_INFO;
LogSeverity min_log_level = kLogInfo;
};
// Gets the active log settings for the current process.
@@ -32,7 +32,7 @@ void SetLogSettings(const LogSettings& settings);
LogSettings GetLogSettings();
// Gets the minimum log level for the current process. Never returs a value
// higher than LOG_FATAL.
// higher than kLogFatal.
int GetMinLogLevel();
class ScopedSetLogSettings {

View File

@@ -7,6 +7,7 @@
#include <iostream>
#include "flutter/fml/build_config.h"
#include "flutter/fml/log_level.h"
#include "flutter/fml/log_settings.h"
#include "flutter/fml/logging.h"
@@ -23,11 +24,11 @@ namespace fml {
namespace {
#if !defined(OS_FUCHSIA)
const char* const kLogSeverityNames[LOG_NUM_SEVERITIES] = {"INFO", "WARNING",
"ERROR", "FATAL"};
const char* const kLogSeverityNames[kLogNumSeverities] = {"INFO", "WARNING",
"ERROR", "FATAL"};
const char* GetNameForLogSeverity(LogSeverity severity) {
if (severity >= LOG_INFO && severity < LOG_NUM_SEVERITIES) {
if (severity >= kLogInfo && severity < kLogNumSeverities) {
return kLogSeverityNames[severity];
}
return "UNKNOWN";
@@ -58,12 +59,12 @@ LogMessage::LogMessage(LogSeverity severity,
: severity_(severity), file_(file), line_(line) {
#if !defined(OS_FUCHSIA)
stream_ << "[";
if (severity >= LOG_INFO) {
if (severity >= kLogInfo) {
stream_ << GetNameForLogSeverity(severity);
} else {
stream_ << "VERBOSE" << -severity;
}
stream_ << ":" << (severity > LOG_INFO ? StripDots(file_) : StripPath(file_))
stream_ << ":" << (severity > kLogInfo ? StripDots(file_) : StripPath(file_))
<< "(" << line_ << ")] ";
#endif
@@ -109,16 +110,16 @@ LogMessage::~LogMessage() {
android_LogPriority priority =
(severity_ < 0) ? ANDROID_LOG_VERBOSE : ANDROID_LOG_UNKNOWN;
switch (severity_) {
case LOG_INFO:
case kLogInfo:
priority = ANDROID_LOG_INFO;
break;
case LOG_WARNING:
case kLogWarning:
priority = ANDROID_LOG_WARN;
break;
case LOG_ERROR:
case kLogError:
priority = ANDROID_LOG_ERROR;
break;
case LOG_FATAL:
case kLogFatal:
priority = ANDROID_LOG_FATAL;
break;
}
@@ -128,16 +129,16 @@ LogMessage::~LogMessage() {
#elif defined(OS_FUCHSIA)
fx_log_severity_t fx_severity;
switch (severity_) {
case LOG_INFO:
case kLogInfo:
fx_severity = FX_LOG_INFO;
break;
case LOG_WARNING:
case kLogWarning:
fx_severity = FX_LOG_WARNING;
break;
case LOG_ERROR:
case kLogError:
fx_severity = FX_LOG_ERROR;
break;
case LOG_FATAL:
case kLogFatal:
fx_severity = FX_LOG_FATAL;
break;
default:
@@ -157,13 +158,13 @@ LogMessage::~LogMessage() {
#endif
}
if (severity_ >= LOG_FATAL) {
if (severity_ >= kLogFatal) {
KillProcess();
}
}
int GetVlogVerbosity() {
return std::max(-1, LOG_INFO - GetMinLogLevel());
return std::max(-1, kLogInfo - GetMinLogLevel());
}
bool ShouldCreateLogMessage(LogSeverity severity) {

View File

@@ -57,7 +57,7 @@ class LogMessage {
int GetVlogVerbosity();
// Returns true if |severity| is at or above the current minimum log level.
// LOG_FATAL and above is always true.
// kLogFatal and above is always true.
bool ShouldCreateLogMessage(LogSeverity severity);
[[noreturn]] void KillProcess();
@@ -74,7 +74,7 @@ bool ShouldCreateLogMessage(LogSeverity severity);
true || (ignored) \
? (void)0 \
: ::fml::LogMessageVoidify() & \
::fml::LogMessage(::fml::LOG_FATAL, 0, 0, nullptr).stream()
::fml::LogMessage(::fml::kLogFatal, 0, 0, nullptr).stream()
#define FML_LOG_IS_ON(severity) \
(::fml::ShouldCreateLogMessage(::fml::LOG_##severity))
@@ -84,7 +84,7 @@ bool ShouldCreateLogMessage(LogSeverity severity);
#define FML_CHECK(condition) \
FML_LAZY_STREAM( \
::fml::LogMessage(::fml::LOG_FATAL, __FILE__, __LINE__, #condition) \
::fml::LogMessage(::fml::kLogFatal, __FILE__, __LINE__, #condition) \
.stream(), \
!(condition))

View File

@@ -42,7 +42,7 @@ static void CheckTwoSkSLsAreLoaded() {
TEST_F(PersistentCacheTest, CanLoadSkSLsFromAsset) {
// Avoid polluting unit tests output by hiding INFO level logging.
fml::LogSettings warning_only = {fml::LOG_WARNING};
fml::LogSettings warning_only = {fml::kLogWarning};
fml::ScopedSetLogSettings scoped_set_log_settings(warning_only);
// The SkSL key is Base32 encoded. "IE" is the encoding of "A" and "II" is the

View File

@@ -104,7 +104,7 @@ void PerformInitializationTasks(Settings& settings) {
{
fml::LogSettings log_settings;
log_settings.min_log_level =
settings.verbose_logging ? fml::LOG_INFO : fml::LOG_ERROR;
settings.verbose_logging ? fml::kLogInfo : fml::kLogError;
fml::SetLogSettings(log_settings);
}