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

Side by Side 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | mojo/public/c/environment/logger.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "mojo/environment/default_logger_impl.h" 5 #include "mojo/environment/default_logger_impl.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 9
10 namespace mojo { 10 namespace mojo {
11 namespace internal { 11 namespace internal {
12 namespace { 12 namespace {
13 13
14 int GetChromiumLogLevel(MojoLogLevel log_level) { 14 // We rely on log levels being the same numerically:
15 // Our log levels correspond, except for "fatal": 15 COMPILE_ASSERT(logging::LOG_VERBOSE == MOJO_LOG_LEVEL_VERBOSE,
16 COMPILE_ASSERT(logging::LOG_VERBOSE == MOJO_LOG_LEVEL_VERBOSE, 16 verbose_log_level_value_mismatch);
17 verbose_log_level_value_mismatch); 17 COMPILE_ASSERT(logging::LOG_INFO == MOJO_LOG_LEVEL_INFO,
18 COMPILE_ASSERT(logging::LOG_INFO == MOJO_LOG_LEVEL_INFO, 18 info_log_level_value_mismatch);
19 info_log_level_value_mismatch); 19 COMPILE_ASSERT(logging::LOG_WARNING == MOJO_LOG_LEVEL_WARNING,
20 COMPILE_ASSERT(logging::LOG_WARNING == MOJO_LOG_LEVEL_WARNING, 20 warning_log_level_value_mismatch);
21 warning_log_level_value_mismatch); 21 COMPILE_ASSERT(logging::LOG_ERROR == MOJO_LOG_LEVEL_ERROR,
22 COMPILE_ASSERT(logging::LOG_ERROR == MOJO_LOG_LEVEL_ERROR, 22 error_log_level_value_mismatch);
23 error_log_level_value_mismatch); 23 COMPILE_ASSERT(logging::LOG_FATAL == MOJO_LOG_LEVEL_FATAL,
24 fatal_log_level_value_mismatch);
24 25
25 return (log_level >= MOJO_LOG_LEVEL_FATAL) ? logging::LOG_FATAL : log_level; 26 int MojoToChromiumLogLevel(MojoLogLevel log_level) {
27 // See the compile asserts above.
28 return static_cast<int>(log_level);
29 }
30
31 MojoLogLevel ChromiumToMojoLogLevel(int chromium_log_level) {
32 // See the compile asserts above.
33 return static_cast<MojoLogLevel>(chromium_log_level);
26 } 34 }
27 35
28 void LogMessage(MojoLogLevel log_level, const char* message) { 36 void LogMessage(MojoLogLevel log_level, const char* message) {
37 int chromium_log_level = MojoToChromiumLogLevel(log_level);
38 int chromium_min_log_level = logging::GetMinLogLevel();
39 // "Fatal" errors aren't suppressable.
40 DCHECK_LE(chromium_min_log_level, logging::LOG_FATAL);
41 if (chromium_log_level < chromium_min_log_level)
42 return;
43
29 // TODO(vtl): Possibly, we should try to pull out the file and line number 44 // TODO(vtl): Possibly, we should try to pull out the file and line number
30 // from |message|. 45 // from |message|.
31 logging::LogMessage(__FILE__, __LINE__, 46 logging::LogMessage(__FILE__, __LINE__, chromium_log_level).stream()
32 GetChromiumLogLevel(log_level)).stream() << message; 47 << message;
48 }
49
50 MojoLogLevel GetMinimumLogLevel() {
51 return ChromiumToMojoLogLevel(logging::GetMinLogLevel());
33 } 52 }
34 53
35 const MojoLogger kDefaultLogger = { 54 const MojoLogger kDefaultLogger = {
36 LogMessage 55 LogMessage,
56 GetMinimumLogLevel
37 }; 57 };
38 58
39 } // namespace 59 } // namespace
40 60
41 const MojoLogger* GetDefaultLoggerImpl() { 61 const MojoLogger* GetDefaultLoggerImpl() {
42 return &kDefaultLogger; 62 return &kDefaultLogger;
43 } 63 }
44 64
45 } // namespace internal 65 } // namespace internal
46 } // namespace mojo 66 } // namespace mojo
OLDNEW
« 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