OLD | NEW |
| (Empty) |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "mojo/environment/default_logger_impl.h" | |
6 | |
7 #include <stdint.h> | |
8 | |
9 #include "base/logging.h" | |
10 #include "base/macros.h" | |
11 | |
12 namespace mojo { | |
13 namespace internal { | |
14 namespace { | |
15 | |
16 // We rely on log levels being the same numerically: | |
17 static_assert(logging::LOG_VERBOSE == MOJO_LOG_LEVEL_VERBOSE, | |
18 "verbose log level value mismatch"); | |
19 static_assert(logging::LOG_INFO == MOJO_LOG_LEVEL_INFO, | |
20 "info log level value mismatch"); | |
21 static_assert(logging::LOG_WARNING == MOJO_LOG_LEVEL_WARNING, | |
22 "warning log level value mismatch"); | |
23 static_assert(logging::LOG_ERROR == MOJO_LOG_LEVEL_ERROR, | |
24 "error log level value mismatch"); | |
25 static_assert(logging::LOG_FATAL == MOJO_LOG_LEVEL_FATAL, | |
26 "fatal log level value mismatch"); | |
27 | |
28 int MojoToChromiumLogLevel(MojoLogLevel log_level) { | |
29 // See the compile asserts above. | |
30 return static_cast<int>(log_level); | |
31 } | |
32 | |
33 MojoLogLevel ChromiumToMojoLogLevel(int chromium_log_level) { | |
34 // See the compile asserts above. | |
35 return static_cast<MojoLogLevel>(chromium_log_level); | |
36 } | |
37 | |
38 void LogMessage(MojoLogLevel log_level, | |
39 const char* source_file, | |
40 uint32_t source_line, | |
41 const char* message) { | |
42 int chromium_log_level = MojoToChromiumLogLevel(log_level); | |
43 int chromium_min_log_level = logging::GetMinLogLevel(); | |
44 // "Fatal" errors aren't suppressable. | |
45 DCHECK_LE(chromium_min_log_level, logging::LOG_FATAL); | |
46 if (chromium_log_level < chromium_min_log_level) | |
47 return; | |
48 | |
49 // TODO(vtl): Possibly, we should try to pull out the file and line number | |
50 // from |message|. | |
51 logging::LogMessage(__FILE__, __LINE__, chromium_log_level).stream() | |
52 << message; | |
53 } | |
54 | |
55 MojoLogLevel GetMinimumLogLevel() { | |
56 return ChromiumToMojoLogLevel(logging::GetMinLogLevel()); | |
57 } | |
58 | |
59 void SetMinimumLogLevel(MojoLogLevel log_level) { | |
60 logging::SetMinLogLevel(MojoToChromiumLogLevel(log_level)); | |
61 } | |
62 | |
63 const MojoLogger kDefaultLogger = { | |
64 LogMessage, | |
65 GetMinimumLogLevel, | |
66 SetMinimumLogLevel | |
67 }; | |
68 | |
69 } // namespace | |
70 | |
71 const MojoLogger* GetDefaultLoggerImpl() { | |
72 return &kDefaultLogger; | |
73 } | |
74 | |
75 } // namespace internal | |
76 } // namespace mojo | |
OLD | NEW |