diff --git a/rtc_base/httpserver.cc b/rtc_base/httpserver.cc index 9d5a890b2d..c36b4327a6 100644 --- a/rtc_base/httpserver.cc +++ b/rtc_base/httpserver.cc @@ -272,7 +272,6 @@ void HttpListenServer::OnReadEvent(AsyncSocket* socket) { AsyncSocket* incoming = listener_->Accept(nullptr); if (incoming) { StreamInterface* stream = new SocketStream(incoming); - //stream = new LoggingAdapter(stream, LS_VERBOSE, "HttpServer", false); HandleConnection(stream); } } diff --git a/rtc_base/logging.cc b/rtc_base/logging.cc index 7ceb2798dd..f468fdd420 100644 --- a/rtc_base/logging.cc +++ b/rtc_base/logging.cc @@ -436,127 +436,6 @@ void LogMessage::OutputToDebug(const std::string& str, } } -////////////////////////////////////////////////////////////////////// -// Logging Helpers -////////////////////////////////////////////////////////////////////// - -void LogMultiline(LoggingSeverity level, const char* label, bool input, - const void* data, size_t len, bool hex_mode, - LogMultilineState* state) { - if (!RTC_LOG_CHECK_LEVEL_V(level)) - return; - - const char * direction = (input ? " << " : " >> "); - - // null data means to flush our count of unprintable characters. - if (!data) { - if (state && state->unprintable_count_[input]) { - RTC_LOG_V(level) << label << direction << "## " - << state->unprintable_count_[input] - << " consecutive unprintable ##"; - state->unprintable_count_[input] = 0; - } - return; - } - - // The ctype classification functions want unsigned chars. - const unsigned char* udata = static_cast(data); - - if (hex_mode) { - const size_t LINE_SIZE = 24; - char hex_line[LINE_SIZE * 9 / 4 + 2], asc_line[LINE_SIZE + 1]; - while (len > 0) { - memset(asc_line, ' ', sizeof(asc_line)); - memset(hex_line, ' ', sizeof(hex_line)); - size_t line_len = std::min(len, LINE_SIZE); - for (size_t i = 0; i < line_len; ++i) { - unsigned char ch = udata[i]; - asc_line[i] = isprint(ch) ? ch : '.'; - hex_line[i*2 + i/4] = hex_encode(ch >> 4); - hex_line[i*2 + i/4 + 1] = hex_encode(ch & 0xf); - } - asc_line[sizeof(asc_line)-1] = 0; - hex_line[sizeof(hex_line)-1] = 0; - RTC_LOG_V(level) << label << direction << asc_line << " " << hex_line - << " "; - udata += line_len; - len -= line_len; - } - return; - } - - size_t consecutive_unprintable = state ? state->unprintable_count_[input] : 0; - - const unsigned char* end = udata + len; - while (udata < end) { - const unsigned char* line = udata; - const unsigned char* end_of_line = strchrn(udata, - end - udata, - '\n'); - if (!end_of_line) { - udata = end_of_line = end; - } else { - udata = end_of_line + 1; - } - - bool is_printable = true; - - // If we are in unprintable mode, we need to see a line of at least - // kMinPrintableLine characters before we'll switch back. - const ptrdiff_t kMinPrintableLine = 4; - if (consecutive_unprintable && ((end_of_line - line) < kMinPrintableLine)) { - is_printable = false; - } else { - // Determine if the line contains only whitespace and printable - // characters. - bool is_entirely_whitespace = true; - for (const unsigned char* pos = line; pos < end_of_line; ++pos) { - if (isspace(*pos)) - continue; - is_entirely_whitespace = false; - if (!isprint(*pos)) { - is_printable = false; - break; - } - } - // Treat an empty line following unprintable data as unprintable. - if (consecutive_unprintable && is_entirely_whitespace) { - is_printable = false; - } - } - if (!is_printable) { - consecutive_unprintable += (udata - line); - continue; - } - // Print out the current line, but prefix with a count of prior unprintable - // characters. - if (consecutive_unprintable) { - RTC_LOG_V(level) << label << direction << "## " << consecutive_unprintable - << " consecutive unprintable ##"; - consecutive_unprintable = 0; - } - // Strip off trailing whitespace. - while ((end_of_line > line) && isspace(*(end_of_line-1))) { - --end_of_line; - } - // Filter out any private data - std::string substr(reinterpret_cast(line), end_of_line - line); - std::string::size_type pos_private = substr.find("Email"); - if (pos_private == std::string::npos) { - pos_private = substr.find("Passwd"); - } - if (pos_private == std::string::npos) { - RTC_LOG_V(level) << label << direction << substr; - } else { - RTC_LOG_V(level) << label << direction << "## omitted for privacy ##"; - } - } - - if (state) { - state->unprintable_count_[input] = consecutive_unprintable; - } -} - ////////////////////////////////////////////////////////////////////// } // namespace rtc diff --git a/rtc_base/logging.h b/rtc_base/logging.h index 5959149417..99a71cae66 100644 --- a/rtc_base/logging.h +++ b/rtc_base/logging.h @@ -254,6 +254,8 @@ class LogMessage { // Logging Helpers ////////////////////////////////////////////////////////////////////// +// TODO(nisse): LogMultiline implementation is deleted, but keep declarations +// until the copy in chromium's webrtc_overrides is deleted too. class LogMultilineState { public: size_t unprintable_count_[2]; diff --git a/rtc_base/stream.cc b/rtc_base/stream.cc index e8c385afc7..b75490bf80 100644 --- a/rtc_base/stream.cc +++ b/rtc_base/stream.cc @@ -887,65 +887,6 @@ StreamResult FifoBuffer::WriteOffsetLocked(const void* buffer, } - -/////////////////////////////////////////////////////////////////////////////// -// LoggingAdapter -/////////////////////////////////////////////////////////////////////////////// - -LoggingAdapter::LoggingAdapter(StreamInterface* stream, LoggingSeverity level, - const std::string& label, bool hex_mode) - : StreamAdapterInterface(stream), level_(level), hex_mode_(hex_mode) { - set_label(label); -} - -void LoggingAdapter::set_label(const std::string& label) { - label_.assign("["); - label_.append(label); - label_.append("]"); -} - -StreamResult LoggingAdapter::Read(void* buffer, size_t buffer_len, - size_t* read, int* error) { - size_t local_read; if (!read) read = &local_read; - StreamResult result = StreamAdapterInterface::Read(buffer, buffer_len, read, - error); - if (result == SR_SUCCESS) { - LogMultiline(level_, label_.c_str(), true, buffer, *read, hex_mode_, &lms_); - } - return result; -} - -StreamResult LoggingAdapter::Write(const void* data, size_t data_len, - size_t* written, int* error) { - size_t local_written; - if (!written) written = &local_written; - StreamResult result = StreamAdapterInterface::Write(data, data_len, written, - error); - if (result == SR_SUCCESS) { - LogMultiline(level_, label_.c_str(), false, data, *written, hex_mode_, - &lms_); - } - return result; -} - -void LoggingAdapter::Close() { - LogMultiline(level_, label_.c_str(), false, nullptr, 0, hex_mode_, &lms_); - LogMultiline(level_, label_.c_str(), true, nullptr, 0, hex_mode_, &lms_); - RTC_LOG_V(level_) << label_ << " Closed locally"; - StreamAdapterInterface::Close(); -} - -void LoggingAdapter::OnEvent(StreamInterface* stream, int events, int err) { - if (events & SE_OPEN) { - RTC_LOG_V(level_) << label_ << " Open"; - } else if (events & SE_CLOSE) { - LogMultiline(level_, label_.c_str(), false, nullptr, 0, hex_mode_, &lms_); - LogMultiline(level_, label_.c_str(), true, nullptr, 0, hex_mode_, &lms_); - RTC_LOG_V(level_) << label_ << " Closed with error: " << err; - } - StreamAdapterInterface::OnEvent(stream, events, err); -} - /////////////////////////////////////////////////////////////////////////////// // StringStream - Reads/Writes to an external std::string /////////////////////////////////////////////////////////////////////////////// diff --git a/rtc_base/stream.h b/rtc_base/stream.h index 171a09f1e0..9dba0ce47d 100644 --- a/rtc_base/stream.h +++ b/rtc_base/stream.h @@ -570,37 +570,6 @@ class FifoBuffer : public StreamInterface { RTC_DISALLOW_COPY_AND_ASSIGN(FifoBuffer); }; -/////////////////////////////////////////////////////////////////////////////// - -class LoggingAdapter : public StreamAdapterInterface { - public: - LoggingAdapter(StreamInterface* stream, LoggingSeverity level, - const std::string& label, bool hex_mode = false); - - void set_label(const std::string& label); - - StreamResult Read(void* buffer, - size_t buffer_len, - size_t* read, - int* error) override; - StreamResult Write(const void* data, - size_t data_len, - size_t* written, - int* error) override; - void Close() override; - - protected: - void OnEvent(StreamInterface* stream, int events, int err) override; - - private: - LoggingSeverity level_; - std::string label_; - bool hex_mode_; - LogMultilineState lms_; - - RTC_DISALLOW_COPY_AND_ASSIGN(LoggingAdapter); -}; - /////////////////////////////////////////////////////////////////////////////// // StringStream - Reads/Writes to an external std::string ///////////////////////////////////////////////////////////////////////////////