// Copyright 2020 The Chromium Authors // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. #ifndef BASE_FUCHSIA_SCOPED_FX_LOGGER_H_ #define BASE_FUCHSIA_SCOPED_FX_LOGGER_H_ #include #include #include #include #include #include #include #include "base/base_export.h" namespace base { // Emits log lines to a logger created via the specified LogSink. // This class is thread-safe. class BASE_EXPORT ScopedFxLogger { public: ScopedFxLogger(); ~ScopedFxLogger(); ScopedFxLogger(ScopedFxLogger&& other); ScopedFxLogger& operator=(ScopedFxLogger&& other); // Returns an instance connected to the process' incoming LogSink service. // The returned instance has a single tag attributing the calling process in // some way (e.g. by Component or process name). // Additional tags may optionally be specified via `tags`. static ScopedFxLogger CreateForProcess( std::vector tags = {}); // Returns an instance connected to the specified LogSink. static ScopedFxLogger CreateFromLogSink( fidl::ClientEnd client_end, std::vector tags = {}); void LogMessage(std::string_view file, uint32_t line_number, std::string_view msg, FuchsiaLogSeverity severity); bool is_valid() const { return socket_.is_valid(); } private: ScopedFxLogger(std::vector tags, zx::socket socket); // For thread-safety these members should be treated as read-only. // They are non-const only to allow move-assignment of ScopedFxLogger. std::vector tags_; zx::socket socket_; }; } // namespace base #endif // BASE_FUCHSIA_SCOPED_FX_LOGGER_H_