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

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

Issue 1765243002: Remove Mojo bindings environment. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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
OLDNEW
(Empty)
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.
4
5 #include "mojo/public/cpp/environment/lib/default_logger.h"
6
7 #include <stdint.h>
8 #include <stdio.h>
9 #include <stdlib.h> // For |abort()|.
10
11 #include <algorithm>
12
13 #include "mojo/public/c/environment/logger.h"
14
15 namespace mojo {
16
17 namespace {
18
19 MojoLogLevel g_minimum_log_level = MOJO_LOG_LEVEL_INFO;
20
21 const char* GetLogLevelString(MojoLogLevel log_level) {
22 if (log_level <= MOJO_LOG_LEVEL_VERBOSE - 3)
23 return "VERBOSE4+";
24 switch (log_level) {
25 case MOJO_LOG_LEVEL_VERBOSE - 2:
26 return "VERBOSE3";
27 case MOJO_LOG_LEVEL_VERBOSE - 1:
28 return "VERBOSE2";
29 case MOJO_LOG_LEVEL_VERBOSE:
30 return "VERBOSE1";
31 case MOJO_LOG_LEVEL_INFO:
32 return "INFO";
33 case MOJO_LOG_LEVEL_WARNING:
34 return "WARNING";
35 case MOJO_LOG_LEVEL_ERROR:
36 return "ERROR";
37 }
38 // Consider everything higher to be fatal.
39 return "FATAL";
40 }
41
42 void LogMessage(MojoLogLevel log_level,
43 const char* source_file,
44 uint32_t source_line,
45 const char* message) {
46 if (log_level < g_minimum_log_level)
47 return;
48
49 // TODO(vtl): Add timestamp also?
50 if (source_file) {
51 fprintf(stderr, "%s: %s(%u): %s\n", GetLogLevelString(log_level),
52 source_file, static_cast<unsigned>(source_line), message);
53 } else {
54 fprintf(stderr, "%s: %s\n", GetLogLevelString(log_level), message);
55 }
56 if (log_level >= MOJO_LOG_LEVEL_FATAL)
57 abort();
58 }
59
60 MojoLogLevel GetMinimumLogLevel() {
61 return g_minimum_log_level;
62 }
63
64 void SetMinimumLogLevel(MojoLogLevel minimum_log_level) {
65 g_minimum_log_level = std::min(minimum_log_level, MOJO_LOG_LEVEL_FATAL);
66 }
67
68 } // namespace
69
70 namespace internal {
71
72 const MojoLogger kDefaultLogger = {LogMessage,
73 GetMinimumLogLevel,
74 SetMinimumLogLevel};
75
76 } // namespace internal
77
78 } // namespace mojo
OLDNEW
« no previous file with comments | « mojo/public/cpp/environment/lib/default_logger.h ('k') | mojo/public/cpp/environment/lib/default_task_tracker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698