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