userver: /data/code/userver/libraries/proto-structs/src/proto-structs/json.cpp Source File
Loading...
Searching...
No Matches
json.cpp
1#include <google/protobuf/json/json.h>
2#include <google/protobuf/message.h>
3
4#include <userver/proto-structs/json.hpp>
5#include <userver/protobuf/string.hpp>
6
7USERVER_NAMESPACE_BEGIN
8
9namespace logging::impl {
10
11logging::LogHelper& LogMessage(logging::LogHelper& h, const google::protobuf::Message& message) {
12 auto options = google::protobuf::json::PrintOptions();
13 options.always_print_primitive_fields = true;
14 options.preserve_proto_field_names = true;
15
16 protobuf::ProtoStringType out;
17 const auto status = google::protobuf::json::MessageToJsonString(message, &out, options);
18 if (status.ok()) {
19 return h << out;
20 }
21 return h << "Failed to log struct: " << status;
22}
23
24} // namespace logging::impl
25
26USERVER_NAMESPACE_END