Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(315)

Side by Side Diff: mojo/public/cpp/environment/lib/default_logger.cc

Issue 334263010: Mojo: Add GetMinimumLogLevel() to the logger interface. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebased Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/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>
11
10 namespace mojo { 12 namespace mojo {
11 namespace { 13 namespace {
12 14
15 MojoLogLevel g_minimum_log_level = MOJO_LOG_LEVEL_INFO;
16
13 const char* GetLogLevelString(MojoLogLevel log_level) { 17 const char* GetLogLevelString(MojoLogLevel log_level) {
14 if (log_level < MOJO_LOG_LEVEL_VERBOSE) 18 if (log_level < MOJO_LOG_LEVEL_VERBOSE)
15 return "VERBOSE"; 19 return "VERBOSE";
16 switch (log_level) { 20 switch (log_level) {
17 case MOJO_LOG_LEVEL_VERBOSE: 21 case MOJO_LOG_LEVEL_VERBOSE:
18 return "VERBOSE"; 22 return "VERBOSE";
19 case MOJO_LOG_LEVEL_INFO: 23 case MOJO_LOG_LEVEL_INFO:
20 return "INFO"; 24 return "INFO";
21 case MOJO_LOG_LEVEL_WARNING: 25 case MOJO_LOG_LEVEL_WARNING:
22 return "WARNING"; 26 return "WARNING";
23 case MOJO_LOG_LEVEL_ERROR: 27 case MOJO_LOG_LEVEL_ERROR:
24 return "ERROR"; 28 return "ERROR";
25 } 29 }
26 // Consider everything higher to be fatal. 30 // Consider everything higher to be fatal.
27 return "FATAL"; 31 return "FATAL";
28 } 32 }
29 33
30 void LogMessage(MojoLogLevel log_level, const char* message) { 34 void LogMessage(MojoLogLevel log_level, const char* message) {
35 if (log_level < g_minimum_log_level)
36 return;
37
31 // TODO(vtl): Add timestamp also? 38 // TODO(vtl): Add timestamp also?
32 fprintf(stderr, "%s:%s\n", GetLogLevelString(log_level), message); 39 fprintf(stderr, "%s:%s\n", GetLogLevelString(log_level), message);
33 if (log_level >= MOJO_LOG_LEVEL_FATAL) 40 if (log_level >= MOJO_LOG_LEVEL_FATAL)
34 abort(); 41 abort();
35 } 42 }
36 43
44 MojoLogLevel GetMinimumLogLevel() {
45 return g_minimum_log_level;
46 }
47
37 const MojoLogger kDefaultLogger = { 48 const MojoLogger kDefaultLogger = {
38 LogMessage 49 LogMessage,
50 GetMinimumLogLevel
39 }; 51 };
40 52
41 } // namespace 53 } // namespace
42 54
55 namespace internal {
56
57 // Declared in mojo/public/cpp/environment/lib/default_logger_internal.h:
58 void SetMinimumLogLevel(MojoLogLevel minimum_log_level) {
59 g_minimum_log_level = std::min(minimum_log_level, MOJO_LOG_LEVEL_FATAL);
60 }
61
62 } // namespace internal
63
64 // Declared in mojo/public/cpp/environment/default_logger.h:
43 const MojoLogger* GetDefaultLogger() { 65 const MojoLogger* GetDefaultLogger() {
44 return &kDefaultLogger; 66 return &kDefaultLogger;
45 } 67 }
46 68
47 } // namespace mojo 69 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/environment/environment.h ('k') | mojo/public/cpp/environment/lib/default_logger_internal.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698