Chromium Code Reviews| 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..9bca0722df6bd883716057c3175a9fcd23ab2830 |
| --- /dev/null |
| +++ b/mojo/services/log/cpp/log_client.h |
| @@ -0,0 +1,48 @@ |
| +// 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 the client library that constructs a MojoLogger that talks to the |
|
viettrungluu
2015/11/20 23:21:51
*a* client library, not *the* client library
vardhan
2015/12/02 00:06:13
Done.
|
| +// Mojo logging service (see ../interfaces/log.mojo). It provides a |MojoLogger| |
| +// implementation for logging, which you may supply to your |mojo::Environment|. |
| +// |
| +// LogClient's life-cycle is similar to |mojo::Environment|. It is only allowed |
| +// to be instantiated once, and remain so for the duration of its use. The |
| +// constructor will initialize some internal state and take ownership of the |
| +// supplied |log_service|. If the pipe to the supplied |log_service| 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. |
| +// |
| +// Example on how to replace the Environment's default logger with LogClient: |
| +// LogPtr log_service; |
| +// // .. bind log_service to proxy .. |
| +// LogClient logclient(std::move(log_service), |
| +// Environment::GetDefaultLogger()); |
| +// Environment::SetDefaultLogger(LogClient::GetLogger()); |
|
viettrungluu
2015/11/20 23:21:51
This example code seems rather bad to me.
In part
vardhan
2015/12/02 00:06:13
I updated the comments to use ApplicationRunner in
|
| +// // At this point, |MOJO_LOG(..) <<| will start talking to the logging |
| +// // service. |
| +class LogClient { |
| + public: |
| + LogClient(LogPtr log_service, const MojoLogger* fallback_logger); |
| + ~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_ |