ServiceWorker: Consolidate version manipulation functions in SWProviderContext
[chromium-blink-merge.git] / mojo / environment / default_logger_impl.cc
blob575feb3989180f0919efb714163836fe5c210040
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, 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;
44 // TODO(vtl): Possibly, we should try to pull out the file and line number
45 // from |message|.
46 logging::LogMessage(__FILE__, __LINE__, chromium_log_level).stream()
47 << message;
50 MojoLogLevel GetMinimumLogLevel() {
51 return ChromiumToMojoLogLevel(logging::GetMinLogLevel());
54 void SetMinimumLogLevel(MojoLogLevel log_level) {
55 logging::SetMinLogLevel(MojoToChromiumLogLevel(log_level));
58 const MojoLogger kDefaultLogger = {
59 LogMessage,
60 GetMinimumLogLevel,
61 SetMinimumLogLevel
64 } // namespace
66 const MojoLogger* GetDefaultLoggerImpl() {
67 return &kDefaultLogger;
70 } // namespace internal
71 } // namespace mojo