| OLD | NEW |
| 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/public/cpp/environment/default_logger.h" | 5 #include "mojo/public/cpp/environment/lib/default_logger.h" |
| 6 | 6 |
| 7 #include <stdio.h> | 7 #include <stdio.h> |
| 8 #include <stdlib.h> // For |abort()|. | 8 #include <stdlib.h> // For |abort()|. |
| 9 | 9 |
| 10 #include <algorithm> | 10 #include <algorithm> |
| 11 | 11 |
| 12 #include "mojo/public/c/environment/logger.h" |
| 13 |
| 12 namespace mojo { | 14 namespace mojo { |
| 15 |
| 13 namespace { | 16 namespace { |
| 14 | 17 |
| 15 MojoLogLevel g_minimum_log_level = MOJO_LOG_LEVEL_INFO; | 18 MojoLogLevel g_minimum_log_level = MOJO_LOG_LEVEL_INFO; |
| 16 | 19 |
| 17 const char* GetLogLevelString(MojoLogLevel log_level) { | 20 const char* GetLogLevelString(MojoLogLevel log_level) { |
| 18 if (log_level < MOJO_LOG_LEVEL_VERBOSE) | 21 if (log_level < MOJO_LOG_LEVEL_VERBOSE) |
| 19 return "VERBOSE"; | 22 return "VERBOSE"; |
| 20 switch (log_level) { | 23 switch (log_level) { |
| 21 case MOJO_LOG_LEVEL_VERBOSE: | 24 case MOJO_LOG_LEVEL_VERBOSE: |
| 22 return "VERBOSE"; | 25 return "VERBOSE"; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 38 // TODO(vtl): Add timestamp also? | 41 // TODO(vtl): Add timestamp also? |
| 39 fprintf(stderr, "%s:%s\n", GetLogLevelString(log_level), message); | 42 fprintf(stderr, "%s:%s\n", GetLogLevelString(log_level), message); |
| 40 if (log_level >= MOJO_LOG_LEVEL_FATAL) | 43 if (log_level >= MOJO_LOG_LEVEL_FATAL) |
| 41 abort(); | 44 abort(); |
| 42 } | 45 } |
| 43 | 46 |
| 44 MojoLogLevel GetMinimumLogLevel() { | 47 MojoLogLevel GetMinimumLogLevel() { |
| 45 return g_minimum_log_level; | 48 return g_minimum_log_level; |
| 46 } | 49 } |
| 47 | 50 |
| 48 const MojoLogger kDefaultLogger = { | 51 void SetMinimumLogLevel(MojoLogLevel minimum_log_level) { |
| 49 LogMessage, | 52 g_minimum_log_level = std::min(minimum_log_level, MOJO_LOG_LEVEL_FATAL); |
| 50 GetMinimumLogLevel | 53 } |
| 51 }; | |
| 52 | 54 |
| 53 } // namespace | 55 } // namespace |
| 54 | 56 |
| 55 namespace internal { | 57 namespace internal { |
| 56 | 58 |
| 57 // Declared in mojo/public/cpp/environment/lib/default_logger_internal.h: | 59 const MojoLogger kDefaultLogger = { |
| 58 void SetMinimumLogLevel(MojoLogLevel minimum_log_level) { | 60 LogMessage, |
| 59 g_minimum_log_level = std::min(minimum_log_level, MOJO_LOG_LEVEL_FATAL); | 61 GetMinimumLogLevel, |
| 60 } | 62 SetMinimumLogLevel |
| 63 }; |
| 61 | 64 |
| 62 } // namespace internal | 65 } // namespace internal |
| 63 | 66 |
| 64 // Declared in mojo/public/cpp/environment/default_logger.h: | |
| 65 const MojoLogger* GetDefaultLogger() { | |
| 66 return &kDefaultLogger; | |
| 67 } | |
| 68 | |
| 69 } // namespace mojo | 67 } // namespace mojo |
| OLD | NEW |