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 342653004: Mojo: Add logging macros (and supporting code) for use in mojo/public/cpp. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: split lines 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
« no previous file with comments | « mojo/mojo_public.gypi ('k') | mojo/public/cpp/environment/lib/logging.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/lib/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" 12 #include "mojo/public/c/environment/logger.h"
13 13
14 namespace mojo { 14 namespace mojo {
15 15
16 namespace { 16 namespace {
17 17
18 MojoLogLevel g_minimum_log_level = MOJO_LOG_LEVEL_INFO; 18 MojoLogLevel g_minimum_log_level = MOJO_LOG_LEVEL_INFO;
19 19
20 const char* GetLogLevelString(MojoLogLevel log_level) { 20 const char* GetLogLevelString(MojoLogLevel log_level) {
21 if (log_level < MOJO_LOG_LEVEL_VERBOSE) 21 if (log_level <= MOJO_LOG_LEVEL_VERBOSE-3)
22 return "VERBOSE"; 22 return "VERBOSE4+";
23 switch (log_level) { 23 switch (log_level) {
24 case MOJO_LOG_LEVEL_VERBOSE-2:
25 return "VERBOSE3";
26 case MOJO_LOG_LEVEL_VERBOSE-1:
27 return "VERBOSE2";
24 case MOJO_LOG_LEVEL_VERBOSE: 28 case MOJO_LOG_LEVEL_VERBOSE:
25 return "VERBOSE"; 29 return "VERBOSE1";
26 case MOJO_LOG_LEVEL_INFO: 30 case MOJO_LOG_LEVEL_INFO:
27 return "INFO"; 31 return "INFO";
28 case MOJO_LOG_LEVEL_WARNING: 32 case MOJO_LOG_LEVEL_WARNING:
29 return "WARNING"; 33 return "WARNING";
30 case MOJO_LOG_LEVEL_ERROR: 34 case MOJO_LOG_LEVEL_ERROR:
31 return "ERROR"; 35 return "ERROR";
32 } 36 }
33 // Consider everything higher to be fatal. 37 // Consider everything higher to be fatal.
34 return "FATAL"; 38 return "FATAL";
35 } 39 }
36 40
37 void LogMessage(MojoLogLevel log_level, const char* message) { 41 void LogMessage(MojoLogLevel log_level, const char* message) {
38 if (log_level < g_minimum_log_level) 42 if (log_level < g_minimum_log_level)
39 return; 43 return;
40 44
41 // TODO(vtl): Add timestamp also? 45 // TODO(vtl): Add timestamp also?
42 fprintf(stderr, "%s:%s\n", GetLogLevelString(log_level), message); 46 fprintf(stderr, "%s: %s\n", GetLogLevelString(log_level), message);
43 if (log_level >= MOJO_LOG_LEVEL_FATAL) 47 if (log_level >= MOJO_LOG_LEVEL_FATAL)
44 abort(); 48 abort();
45 } 49 }
46 50
47 MojoLogLevel GetMinimumLogLevel() { 51 MojoLogLevel GetMinimumLogLevel() {
48 return g_minimum_log_level; 52 return g_minimum_log_level;
49 } 53 }
50 54
51 void SetMinimumLogLevel(MojoLogLevel minimum_log_level) { 55 void SetMinimumLogLevel(MojoLogLevel minimum_log_level) {
52 g_minimum_log_level = std::min(minimum_log_level, MOJO_LOG_LEVEL_FATAL); 56 g_minimum_log_level = std::min(minimum_log_level, MOJO_LOG_LEVEL_FATAL);
53 } 57 }
54 58
55 } // namespace 59 } // namespace
56 60
57 namespace internal { 61 namespace internal {
58 62
59 const MojoLogger kDefaultLogger = { 63 const MojoLogger kDefaultLogger = {
60 LogMessage, 64 LogMessage,
61 GetMinimumLogLevel, 65 GetMinimumLogLevel,
62 SetMinimumLogLevel 66 SetMinimumLogLevel
63 }; 67 };
64 68
65 } // namespace internal 69 } // namespace internal
66 70
67 } // namespace mojo 71 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/mojo_public.gypi ('k') | mojo/public/cpp/environment/lib/logging.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698