Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1727)

Unified Diff: mojo/environment/default_logger_impl.cc

Issue 334263010: Mojo: Add GetMinimumLogLevel() to the logger interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | mojo/public/c/environment/logger.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: mojo/environment/default_logger_impl.cc
diff --git a/mojo/environment/default_logger_impl.cc b/mojo/environment/default_logger_impl.cc
index a2b06198a3c4d8aca090cedf1e08ff4375867349..76f76f4a27da970f16f242a048d26d586678979a 100644
--- a/mojo/environment/default_logger_impl.cc
+++ b/mojo/environment/default_logger_impl.cc
@@ -11,29 +11,49 @@ namespace mojo {
namespace internal {
namespace {
-int GetChromiumLogLevel(MojoLogLevel log_level) {
- // Our log levels correspond, except for "fatal":
- COMPILE_ASSERT(logging::LOG_VERBOSE == MOJO_LOG_LEVEL_VERBOSE,
- verbose_log_level_value_mismatch);
- COMPILE_ASSERT(logging::LOG_INFO == MOJO_LOG_LEVEL_INFO,
- info_log_level_value_mismatch);
- COMPILE_ASSERT(logging::LOG_WARNING == MOJO_LOG_LEVEL_WARNING,
- warning_log_level_value_mismatch);
- COMPILE_ASSERT(logging::LOG_ERROR == MOJO_LOG_LEVEL_ERROR,
- error_log_level_value_mismatch);
-
- return (log_level >= MOJO_LOG_LEVEL_FATAL) ? logging::LOG_FATAL : log_level;
+// We rely on log levels being the same numerically:
+COMPILE_ASSERT(logging::LOG_VERBOSE == MOJO_LOG_LEVEL_VERBOSE,
+ verbose_log_level_value_mismatch);
+COMPILE_ASSERT(logging::LOG_INFO == MOJO_LOG_LEVEL_INFO,
+ info_log_level_value_mismatch);
+COMPILE_ASSERT(logging::LOG_WARNING == MOJO_LOG_LEVEL_WARNING,
+ warning_log_level_value_mismatch);
+COMPILE_ASSERT(logging::LOG_ERROR == MOJO_LOG_LEVEL_ERROR,
+ error_log_level_value_mismatch);
+COMPILE_ASSERT(logging::LOG_FATAL == MOJO_LOG_LEVEL_FATAL,
+ fatal_log_level_value_mismatch);
+
+int MojoToChromiumLogLevel(MojoLogLevel log_level) {
+ // See the compile asserts above.
+ return static_cast<int>(log_level);
+}
+
+MojoLogLevel ChromiumToMojoLogLevel(int chromium_log_level) {
+ // See the compile asserts above.
+ return static_cast<MojoLogLevel>(chromium_log_level);
}
void LogMessage(MojoLogLevel log_level, const char* message) {
+ int chromium_log_level = MojoToChromiumLogLevel(log_level);
+ int chromium_min_log_level = logging::GetMinLogLevel();
+ // "Fatal" errors aren't suppressable.
+ DCHECK_LE(chromium_min_log_level, logging::LOG_FATAL);
+ if (chromium_log_level < chromium_min_log_level)
+ return;
+
// TODO(vtl): Possibly, we should try to pull out the file and line number
// from |message|.
- logging::LogMessage(__FILE__, __LINE__,
- GetChromiumLogLevel(log_level)).stream() << message;
+ logging::LogMessage(__FILE__, __LINE__, chromium_log_level).stream()
+ << message;
+}
+
+MojoLogLevel GetMinimumLogLevel() {
+ return ChromiumToMojoLogLevel(logging::GetMinLogLevel());
}
const MojoLogger kDefaultLogger = {
- LogMessage
+ LogMessage,
+ GetMinimumLogLevel
};
} // namespace
« no previous file with comments | « no previous file | mojo/public/c/environment/logger.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698