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

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

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

Powered by Google App Engine
This is Rietveld 408576698