Skip to content

Commit

Permalink
fix
Browse files Browse the repository at this point in the history
  • Loading branch information
nshestakov committed Mar 6, 2024
1 parent f93aa1b commit 3a05c56
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 13 deletions.
9 changes: 2 additions & 7 deletions ydb/core/client/server/grpc_server.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include <library/cpp/json/json_writer.h>

#include <util/string/join.h>
#include <util/system/env.h>

#include <google/protobuf/text_format.h>

Expand Down Expand Up @@ -79,8 +78,6 @@ class TSimpleRequest
, InProgress_(false)
{
LOG_DEBUG(ActorSystem, NKikimrServices::GRPC_SERVER, "[%p] created request Name# %s", this, Name);

LogBody = "BODY" == GetEnv("YDB_LOGGING");
}

~TSimpleRequest() {
Expand Down Expand Up @@ -271,7 +268,7 @@ class TSimpleRequest
void Finish(const TOut& resp, ui32 status) {
auto makeResponseString = [&] {
TString x;
if (LogBody) {
if (NYdbGrpc::LogBodyEnabled) {
google::protobuf::TextFormat::Printer printer;
printer.SetSingleLineMode(true);
printer.PrintToString(resp, &x);
Expand Down Expand Up @@ -310,7 +307,7 @@ class TSimpleRequest
auto makeRequestString = [&] {
TString resp;
if (ok) {
if (LogBody) {
if (NYdbGrpc::LogBodyEnabled) {
google::protobuf::TextFormat::Printer printer;
printer.SetSingleLineMode(true);
printer.PrintToString(Request, &resp);
Expand Down Expand Up @@ -403,8 +400,6 @@ class TSimpleRequest
bool RequestDestroyed_ = false;
bool CallInProgress_ = false;
bool Finished_ = false;

bool LogBody;
};

} // namespace
Expand Down
20 changes: 14 additions & 6 deletions ydb/core/grpc_streaming/grpc_streaming.h
Original file line number Diff line number Diff line change
Expand Up @@ -350,9 +350,13 @@ class TGRpcStreamingRequest final
auto dumpResultText = [&] {
TString text;
if (status == NYdbGrpc::EQueueEventStatus::OK) {
google::protobuf::TextFormat::Printer printer;
printer.SetSingleLineMode(true);
printer.PrintToString(ReadInProgress->Record, &text);
if (NYdbGrpc::LogBodyEnabled) {
google::protobuf::TextFormat::Printer printer;
printer.SetSingleLineMode(true);
printer.PrintToString(ReadInProgress->Record, &text);
} else {
text = "<hidden>";
}
} else {
text = "<not ok>";
}
Expand Down Expand Up @@ -402,9 +406,13 @@ class TGRpcStreamingRequest final
bool Write(TOut&& message, const grpc::WriteOptions& options = { }, const grpc::Status* status = nullptr) {
auto dumpMessageText = [&] {
TString text;
google::protobuf::TextFormat::Printer printer;
printer.SetSingleLineMode(true);
printer.PrintToString(message, &text);
if (NYdbGrpc::LogBodyEnabled) {
google::protobuf::TextFormat::Printer printer;
printer.SetSingleLineMode(true);
printer.PrintToString(message, &text);
} else {
text = "<hidden>";
}
return text;
};

Expand Down
4 changes: 4 additions & 0 deletions ydb/library/grpc/server/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
#include <library/cpp/logger/priority.h>

#include <util/generic/ptr.h>
#include <util/system/env.h>


namespace NYdbGrpc {

static bool LogBodyEnabled = "BODY" == GetEnv("YDB_GRPC_SERVER_LOGGING");

class TLogger: public TThrRefBase {
protected:
TLogger() = default;
Expand Down

0 comments on commit 3a05c56

Please sign in to comment.