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

Unified Diff: mojo/public/cpp/environment/lib/default_logger.cc

Issue 330933004: Mojo: Add basic logging facilities to environment. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: 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 side-by-side diff with in-line comments
Download patch
Index: mojo/public/cpp/environment/lib/default_logger.cc
diff --git a/mojo/public/cpp/environment/lib/default_logger.cc b/mojo/public/cpp/environment/lib/default_logger.cc
new file mode 100644
index 0000000000000000000000000000000000000000..100b0d185ef792ef6466a0f2647f5af4651268a4
--- /dev/null
+++ b/mojo/public/cpp/environment/lib/default_logger.cc
@@ -0,0 +1,47 @@
+// Copyright 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "mojo/public/cpp/environment/default_logger.h"
+
+#include <stdio.h>
+#include <stdlib.h> // For |abort()|.
+
+namespace mojo {
+namespace {
+
+const char* GetLogLevelString(MojoLogLevel log_level) {
+ if (log_level < MOJO_LOG_LEVEL_VERBOSE)
+ return "VERBOSE";
+ switch (log_level) {
+ case MOJO_LOG_LEVEL_VERBOSE:
+ return "VERBOSE";
+ case MOJO_LOG_LEVEL_INFO:
+ return "INFO";
+ case MOJO_LOG_LEVEL_WARNING:
+ return "WARNING";
+ case MOJO_LOG_LEVEL_ERROR:
+ return "ERROR";
+ }
+ // Consider everything higher to be fatal.
+ return "FATAL";
+}
+
+void LogMessage(MojoLogLevel log_level, const char* message) {
+ // TODO(vtl): Add timestamp also?
+ fprintf(stderr, "%s:%s\n", GetLogLevelString(log_level), message);
darin (slow to review) 2014/06/14 06:08:23 nit: it might be nice to add a space after the col
+ if (log_level >= MOJO_LOG_LEVEL_FATAL)
+ abort();
+}
+
+const MojoLogger kDefaultLogger = {
+ LogMessage
+};
+
+} // namespace
+
+const MojoLogger* GetDefaultLogger() {
+ return &kDefaultLogger;
+}
+
+} // namespace mojo

Powered by Google App Engine
This is Rietveld 408576698