userver: userver/logging/json_string.hpp Source File
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages Concepts
json_string.hpp
Go to the documentation of this file.
1#pragma once
2
3/// @file userver/logging/json_string.hpp
4/// @brief @copybrief logging::JsonString
5
6#include <string>
7#include <string_view>
8
9#include <userver/formats/json_fwd.hpp>
10
11USERVER_NAMESPACE_BEGIN
12
13namespace logging {
14
15/// One line json string.
16/// JSON log formats write such tags directly as a sub-JSON, without packing them in a string.
18public:
19 /// @brief Constructs from provided json object.
20 /// The generated json string is an one line string.
21 /*implicit*/ JsonString(const formats::json::Value& value);
22
23 /// @brief Constructs from provided json string. It is the user's
24 /// responsibility to ensure that the input json string is valid.
25 /// New lines will be removed during construction.
26 explicit JsonString(std::string json) noexcept;
27
28 /// @brief Constructs null json (see GetValue for details)
29 JsonString() noexcept = default;
30
31 JsonString(JsonString&&) noexcept = default;
32 JsonString(const JsonString&) = default;
33
34 JsonString& operator=(JsonString&&) noexcept = default;
35 JsonString& operator=(const JsonString&) = default;
36
37 /// @brief Returns view to json
38 std::string_view GetView() const noexcept;
39
40private:
41 std::string json_;
42};
43
44void WriteToStream(const JsonString& value, formats::json::StringBuilder& sw);
45
46} // namespace logging
47
48USERVER_NAMESPACE_END