Update mojo sdk to rev 1dc8a9a5db73d3718d99917fadf31f5fb2ebad4f
[chromium-blink-merge.git] / mojo / environment / default_logger_impl.cc
blob9a321006cfe0ff97a370ad9cfe9f3e942b4f7952
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"
10 namespace mojo {
11 namespace internal {
12 namespace {
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,
38 uint32_t source_line,
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)
45 return;
47 // TODO(vtl): Possibly, we should try to pull out the file and line number
48 // from |message|.
49 logging::LogMessage(__FILE__, __LINE__, chromium_log_level).stream()
50 << message;
53 MojoLogLevel GetMinimumLogLevel() {
54 return ChromiumToMojoLogLevel(logging::GetMinLogLevel());
57 void SetMinimumLogLevel(MojoLogLevel log_level) {
58 logging::SetMinLogLevel(MojoToChromiumLogLevel(log_level));
61 const MojoLogger kDefaultLogger = {
62 LogMessage,
63 GetMinimumLogLevel,
64 SetMinimumLogLevel
67 } // namespace
69 const MojoLogger* GetDefaultLoggerImpl() {
70 return &kDefaultLogger;
73 } // namespace internal
74 } // namespace mojo