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 the client library that constructs a logger to talk to the Mojo |
| 15 // logging service (see ../interfaces/log.mojo). It exposes a MojoLogger |
| 16 // interface for logging, which you may supply to your |mojo::Environment|. |
| 17 // |
| 18 // LogClient is only allowed to be instantiated once, and remain so for the |
| 19 // duration of its use. The constructor will initialize some internal state and |
| 20 // take ownership of the supplied |log_service|. If the pipe to the supplied |
| 21 // |log_service| fails, LogClient will fallback to the supplied |
| 22 // |fallback_logger|. |
| 23 // |
| 24 // This class is thread-safe. |
| 25 // |
| 26 // Example on how to replace the Environment's default logger with LogClient: |
| 27 // LogPtr log_service; |
| 28 // // .. bind log_service to proxy .. |
| 29 // LogClient logclient(std::move(log_service), |
| 30 // Environment::GetDefaultLogger()); |
| 31 // Environment::SetDefaultLogger(LogClient::GetLogger()); |
| 32 // // At this point, |MOJO_LOG(..) <<| will start talking to the logging |
| 33 // service. |
| 34 class LogClient { |
| 35 public: |
| 36 LogClient(LogPtr log_service, const MojoLogger* fallback_logger); |
| 37 ~LogClient(); |
| 38 |
| 39 // You can retrieve the logger before any LogClient instance is created, but |
| 40 // any uses of the logger may assert-fail. |
| 41 static const MojoLogger* GetLogger(); |
| 42 }; |
| 43 |
| 44 } // namespace log |
| 45 } // namespace mojo |
| 46 |
| 47 #endif // MOJO_SERVICES_LOG_CPP_LOG_CLIENT_H_ |
OLD | NEW |