[fuchsia] Clean up logging to the Fuchsia logger
This improves readability for the code responsible for logging to the Fuchsia logger service. This also skips instantiating a variable if no logger is available. Bug: 1188820 Change-Id: I39d22a2f8a934e115af7ad95728432a60bfc2dab Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2819363 Reviewed-by: David Dorwin <ddorwin@chromium.org> Reviewed-by: Wez <wez@chromium.org> Commit-Queue: Fabrice de Gans-Riberi <fdegans@chromium.org> Cr-Commit-Position: refs/heads/master@{#873045}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
092c77c837
commit
fb94dff8bf
@@ -346,6 +346,30 @@ void CloseLogFileUnlocked() {
|
|||||||
g_logging_destination &= ~LOG_TO_FILE;
|
g_logging_destination &= ~LOG_TO_FILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#if defined(OS_FUCHSIA)
|
||||||
|
|
||||||
|
inline fx_log_severity_t LogSeverityToFuchsiaLogSeverity(LogSeverity severity) {
|
||||||
|
switch (severity) {
|
||||||
|
case LOGGING_INFO:
|
||||||
|
return FX_LOG_INFO;
|
||||||
|
case LOGGING_WARNING:
|
||||||
|
return FX_LOG_WARNING;
|
||||||
|
case LOGGING_ERROR:
|
||||||
|
return FX_LOG_ERROR;
|
||||||
|
case LOGGING_FATAL:
|
||||||
|
// Don't use FX_LOG_FATAL, otherwise fx_logger_log() will abort().
|
||||||
|
return FX_LOG_ERROR;
|
||||||
|
}
|
||||||
|
if (severity > -3) {
|
||||||
|
// LOGGING_VERBOSE levels 1 and 2.
|
||||||
|
return FX_LOG_DEBUG;
|
||||||
|
}
|
||||||
|
// LOGGING_VERBOSE levels 3 and higher, or incorrect levels.
|
||||||
|
return FX_LOG_TRACE;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // defined (OS_FUCHSIA)
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
#if defined(DCHECK_IS_CONFIGURABLE)
|
#if defined(DCHECK_IS_CONFIGURABLE)
|
||||||
@@ -401,7 +425,7 @@ bool BaseInitLoggingImpl(const LoggingSettings& settings) {
|
|||||||
const char* log_tag_data = log_tag.data();
|
const char* log_tag_data = log_tag.data();
|
||||||
|
|
||||||
fx_logger_config_t config = {
|
fx_logger_config_t config = {
|
||||||
.min_severity = g_vlog_info ? FX_LOG_DEBUG : FX_LOG_INFO,
|
.min_severity = g_vlog_info ? FX_LOG_TRACE : FX_LOG_INFO,
|
||||||
.console_fd = -1,
|
.console_fd = -1,
|
||||||
.tags = &log_tag_data,
|
.tags = &log_tag_data,
|
||||||
.num_tags = 1,
|
.num_tags = 1,
|
||||||
@@ -778,35 +802,14 @@ LogMessage::~LogMessage() {
|
|||||||
__android_log_write(priority, kAndroidLogTag, str_newline.c_str());
|
__android_log_write(priority, kAndroidLogTag, str_newline.c_str());
|
||||||
#endif
|
#endif
|
||||||
#elif defined(OS_FUCHSIA)
|
#elif defined(OS_FUCHSIA)
|
||||||
fx_log_severity_t severity = FX_LOG_INFO;
|
|
||||||
switch (severity_) {
|
|
||||||
case LOGGING_INFO:
|
|
||||||
severity = FX_LOG_INFO;
|
|
||||||
break;
|
|
||||||
case LOGGING_WARNING:
|
|
||||||
severity = FX_LOG_WARNING;
|
|
||||||
break;
|
|
||||||
case LOGGING_ERROR:
|
|
||||||
severity = FX_LOG_ERROR;
|
|
||||||
break;
|
|
||||||
case LOGGING_FATAL:
|
|
||||||
// Don't use FX_LOG_FATAL, otherwise fx_logger_log() will abort().
|
|
||||||
severity = FX_LOG_ERROR;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
// TODO(https://crbug.com/1188820): Integrate verbose levels with the switch
|
|
||||||
// statement.
|
|
||||||
if (severity_ <= LOGGING_VERBOSE) {
|
|
||||||
severity = FX_LOG_DEBUG;
|
|
||||||
}
|
|
||||||
|
|
||||||
fx_logger_t* logger = fx_log_get_logger();
|
fx_logger_t* logger = fx_log_get_logger();
|
||||||
if (logger) {
|
if (logger) {
|
||||||
// Temporarily remove the trailing newline from |str_newline|'s C-string
|
// Temporarily remove the trailing newline from |str_newline|'s C-string
|
||||||
// representation, since fx_logger will add a newline of its own.
|
// representation, since fx_logger will add a newline of its own.
|
||||||
str_newline.pop_back();
|
str_newline.pop_back();
|
||||||
fx_logger_log_with_source(logger, severity, nullptr, file_, line_,
|
fx_logger_log_with_source(
|
||||||
str_newline.c_str() + message_start_);
|
logger, LogSeverityToFuchsiaLogSeverity(severity_), nullptr, file_,
|
||||||
|
line_, str_newline.c_str() + message_start_);
|
||||||
str_newline.push_back('\n');
|
str_newline.push_back('\n');
|
||||||
}
|
}
|
||||||
#endif // OS_FUCHSIA
|
#endif // OS_FUCHSIA
|
||||||
|
Reference in New Issue
Block a user