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.
5 #include "mojo/environment/default_logger_impl.h"
7 #include "base/logging.h"
8 #include "base/macros.h"
14 // We rely on log levels being the same numerically:
15 COMPILE_ASSERT(logging::LOG_VERBOSE
== MOJO_LOG_LEVEL_VERBOSE
,
16 verbose_log_level_value_mismatch
);
17 COMPILE_ASSERT(logging::LOG_INFO
== MOJO_LOG_LEVEL_INFO
,
18 info_log_level_value_mismatch
);
19 COMPILE_ASSERT(logging::LOG_WARNING
== MOJO_LOG_LEVEL_WARNING
,
20 warning_log_level_value_mismatch
);
21 COMPILE_ASSERT(logging::LOG_ERROR
== MOJO_LOG_LEVEL_ERROR
,
22 error_log_level_value_mismatch
);
23 COMPILE_ASSERT(logging::LOG_FATAL
== MOJO_LOG_LEVEL_FATAL
,
24 fatal_log_level_value_mismatch
);
26 int MojoToChromiumLogLevel(MojoLogLevel log_level
) {
27 // See the compile asserts above.
28 return static_cast<int>(log_level
);
31 MojoLogLevel
ChromiumToMojoLogLevel(int chromium_log_level
) {
32 // See the compile asserts above.
33 return static_cast<MojoLogLevel
>(chromium_log_level
);
36 void LogMessage(MojoLogLevel log_level
,
37 const char* source_file
,
39 const char* message
) {
40 int chromium_log_level
= MojoToChromiumLogLevel(log_level
);
41 int chromium_min_log_level
= logging::GetMinLogLevel();
42 // "Fatal" errors aren't suppressable.
43 DCHECK_LE(chromium_min_log_level
, logging::LOG_FATAL
);
44 if (chromium_log_level
< chromium_min_log_level
)
47 // TODO(vtl): Possibly, we should try to pull out the file and line number
49 logging::LogMessage(__FILE__
, __LINE__
, chromium_log_level
).stream()
53 MojoLogLevel
GetMinimumLogLevel() {
54 return ChromiumToMojoLogLevel(logging::GetMinLogLevel());
57 void SetMinimumLogLevel(MojoLogLevel log_level
) {
58 logging::SetMinLogLevel(MojoToChromiumLogLevel(log_level
));
61 const MojoLogger kDefaultLogger
= {
69 const MojoLogger
* GetDefaultLoggerImpl() {
70 return &kDefaultLogger
;
73 } // namespace internal