Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2015 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 #ifndef MOJO_SERVICES_LOG_CPP_LOG_CLIENT_H_ | |
| 6 #define MOJO_SERVICES_LOG_CPP_LOG_CLIENT_H_ | |
| 7 | |
| 8 #include "mojo/public/c/environment/logger.h" | |
| 9 #include "mojo/services/log/interfaces/log.mojom.h" | |
| 10 | |
| 11 namespace mojo { | |
| 12 namespace log { | |
| 13 | |
| 14 // This is a client library that constructs a MojoLogger that talks to a | |
| 15 // Mojo logging service (see ../interfaces/log.mojo). It provides a |MojoLogger| | |
| 16 // implementation for logging, which you may use the default logger. | |
| 17 // | |
| 18 // LogClient is a singleton, and it must live for duration of its logger's use. | |
| 19 // The constructor will initialize some internal state and take ownership of the | |
| 20 // supplied |log_service|. If the pipe to the supplied |log_service| ever fails, | |
| 21 // |LogClient| will fallback to using the supplied |fallback_logger|. | |
| 22 // | |
| 23 // This class itself is not thread-safe, but the MojoLogger returned by | |
| 24 // LogClient::GetLogger() is thread-safe for the life time of LogClient. | |
| 25 // | |
| 26 // An example app that sets up the LogClient and uses it as the default logger: | |
| 27 // | |
| 28 // class MyDelegate : public mojo::ApplicationDelegate { | |
| 29 // public: | |
| 30 // void Initialize(mojo::ApplicationImpl* app) override { | |
| 31 // LogPtr log; | |
| 32 // app->ConnectToService("mojo:log", &log); | |
| 33 // log_client_.reset(new LogClient(std::move(log), | |
| 34 // ApplicationRunner::GetDefaultLogger())); | |
| 35 // mojo::ApplicationRunner::SetDefaultLogger(LogClient::GetLogger()); | |
| 36 // } | |
| 37 // | |
| 38 // private: | |
| 39 // std::unique_ptr<mojo::log::LogClient> log_client_; | |
| 40 // }; | |
| 41 // | |
| 42 // MojoResult MojoMain(MojoHandle app_request) { | |
| 43 // mojo::ApplicationRunner runner(new MyDelegate); | |
| 44 // return runner.Run(app_request); | |
| 45 // } | |
| 46 // | |
| 47 // Here, we see that the LogClient lives for the duration of its | |
| 48 // ApplicationDelegate, which lives for the duration of its ApplicationRunner. | |
| 49 class LogClient { | |
| 50 public: | |
| 51 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.
| |
| 52 ~LogClient(); | |
| 53 | |
| 54 // You can retrieve the logger before any LogClient instance is created, but | |
| 55 // any uses of the logger may assert-fail. | |
| 56 static const MojoLogger* GetLogger(); | |
| 57 }; | |
| 58 | |
| 59 } // namespace log | |
| 60 } // namespace mojo | |
| 61 | |
| 62 #endif // MOJO_SERVICES_LOG_CPP_LOG_CLIENT_H_ | |
| OLD | NEW |