diff --git a/src/brpc/builtin/rpcz_service.cpp b/src/brpc/builtin/rpcz_service.cpp index d4374e47de..3625c0684b 100644 --- a/src/brpc/builtin/rpcz_service.cpp +++ b/src/brpc/builtin/rpcz_service.cpp @@ -194,7 +194,7 @@ static void PrintAnnotations( while (extractors[i]->PopAnnotation(cur_time, &anno_time, &a)) { PrintRealTime(os, anno_time); PrintElapse(os, anno_time, last_time); - os << ' ' << a; + os << ' ' << WebEscape(a); if (a.empty() || butil::back_char(a) != '\n') { os << '\n'; } @@ -249,7 +249,7 @@ static void PrintClientSpan( if (abs_remote_side.ip == loopback_ip) { abs_remote_side.ip = butil::my_ip(); } - os << " Requesting " << span.full_method_name() << '@' << remote_side + os << " Requesting " << WebEscape(span.full_method_name()) << '@' << remote_side << ' ' << protocol_name << ' ' << LOG_ID_STR << '='; if (FLAGS_rpcz_hex_log_id) { os << Hex(span.log_id()); @@ -346,7 +346,7 @@ static void PrintServerSpan(std::ostream& os, const RpczSpan& span, os, span.start_callback_real_us(), &last_time, extr, ARRAY_SIZE(extr))) { entered_user_method = true; - os << " Enter " << span.full_method_name() << std::endl; + os << " Enter " << WebEscape(span.full_method_name()) << std::endl; } const int nclient = span.client_spans_size(); @@ -359,7 +359,7 @@ static void PrintServerSpan(std::ostream& os, const RpczSpan& span, os, span.start_send_real_us(), &last_time, extr, ARRAY_SIZE(extr))) { if (entered_user_method) { - os << " Leave " << span.full_method_name() << std::endl; + os << " Leave " << WebEscape(span.full_method_name()) << std::endl; } else { os << " Responding" << std::endl; } @@ -665,7 +665,7 @@ void RpczService::default_method(::google::protobuf::RpcController* cntl_base, } else { os << span.log_id(); } - os << ' ' << span.full_method_name() << '(' << span.request_size() + os << ' ' << WebEscape(span.full_method_name()) << '(' << span.request_size() << ")=" << span.response_size(); if (span.error_code() == 0) { diff --git a/src/brpc/controller.cpp b/src/brpc/controller.cpp index 338ad66c73..7ff0d26a01 100644 --- a/src/brpc/controller.cpp +++ b/src/brpc/controller.cpp @@ -1391,6 +1391,12 @@ void WebEscape(const std::string& source, std::string* output) { } } +std::string WebEscape(const std::string& source) { + std::string output; + WebEscape(source, &output); + return output; +} + void Controller::reset_sampled_request(SampledRequest* req) { delete _sampled_request; _sampled_request = req; diff --git a/src/brpc/controller.h b/src/brpc/controller.h index f27dd54f86..8298826963 100644 --- a/src/brpc/controller.h +++ b/src/brpc/controller.h @@ -844,6 +844,7 @@ google::protobuf::Closure* DoNothing(); // Convert non-web symbols to web equivalence. void WebEscape(const std::string& source, std::string* output); +std::string WebEscape(const std::string& source); // True if Ctrl-C is ever pressed. bool IsAskedToQuit();