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

Unified Diff: mojo/services/log/cpp/log_client.h

Issue 1447273002: Mojo Log service and a thread-safe client library. (Closed) Base URL: https://github.com/domokit/mojo.git@master
Patch Set: oops, forgot to #include "base/macros.h" in log_impl.h Created 5 years 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/services/log/cpp/log_client.h
diff --git a/mojo/services/log/cpp/log_client.h b/mojo/services/log/cpp/log_client.h
new file mode 100644
index 0000000000000000000000000000000000000000..cf7370b8b88838010b05af029361e6a7d5b58e8e
--- /dev/null
+++ b/mojo/services/log/cpp/log_client.h
@@ -0,0 +1,62 @@
+// Copyright 2015 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.
+
+#ifndef MOJO_SERVICES_LOG_CPP_LOG_CLIENT_H_
+#define MOJO_SERVICES_LOG_CPP_LOG_CLIENT_H_
+
+#include "mojo/public/c/environment/logger.h"
+#include "mojo/services/log/interfaces/log.mojom.h"
+
+namespace mojo {
+namespace log {
+
+// This is a client library that constructs a MojoLogger that talks to a
+// Mojo logging service (see ../interfaces/log.mojo). It provides a |MojoLogger|
+// implementation for logging, which you may use the default logger.
+//
+// LogClient is a singleton, and it must live for duration of its logger's use.
+// The constructor will initialize some internal state and take ownership of the
+// supplied |log_service|. If the pipe to the supplied |log_service| ever fails,
+// |LogClient| will fallback to using the supplied |fallback_logger|.
+//
+// This class itself is not thread-safe, but the MojoLogger returned by
+// LogClient::GetLogger() is thread-safe for the life time of LogClient.
+//
+// An example app that sets up the LogClient and uses it as the default logger:
+//
+// class MyDelegate : public mojo::ApplicationDelegate {
+// public:
+// void Initialize(mojo::ApplicationImpl* app) override {
+// LogPtr log;
+// app->ConnectToService("mojo:log", &log);
+// log_client_.reset(new LogClient(std::move(log),
+// ApplicationRunner::GetDefaultLogger()));
+// mojo::ApplicationRunner::SetDefaultLogger(LogClient::GetLogger());
+// }
+//
+// private:
+// std::unique_ptr<mojo::log::LogClient> log_client_;
+// };
+//
+// MojoResult MojoMain(MojoHandle app_request) {
+// mojo::ApplicationRunner runner(new MyDelegate);
+// return runner.Run(app_request);
+// }
+//
+// Here, we see that the LogClient lives for the duration of its
+// ApplicationDelegate, which lives for the duration of its ApplicationRunner.
+class LogClient {
+ public:
+ LogClient(LogPtr log_service, const MojoLogger* fallback_logger);
viettrungluu 2015/12/03 19:13:25 Rather than exposing this class, maybe you should
vardhan 2015/12/15 01:55:06 Done.
+ ~LogClient();
+
+ // You can retrieve the logger before any LogClient instance is created, but
+ // any uses of the logger may assert-fail.
+ static const MojoLogger* GetLogger();
+};
+
+} // namespace log
+} // namespace mojo
+
+#endif // MOJO_SERVICES_LOG_CPP_LOG_CLIENT_H_

Powered by Google App Engine
This is Rietveld 408576698