From 55378f48b1c7b7d3e06b79718a5d76d09bf8dede Mon Sep 17 00:00:00 2001 From: Jonas Olsson Date: Fri, 25 May 2018 10:23:10 +0200 Subject: [PATCH] Remove some streams from rtc_base/ Bug: webrtc:8982 Change-Id: Id372dde980fae493debf20873b6aeee8a7f1b045 Reviewed-on: https://webrtc-review.googlesource.com/78781 Commit-Queue: Jonas Olsson Reviewed-by: Karl Wiberg Cr-Commit-Position: refs/heads/master@{#23396} --- rtc_base/BUILD.gn | 1 + rtc_base/filerotatingstream.cc | 25 +++++++++++++------------ rtc_base/logsinks.cc | 4 ++-- rtc_base/macutils.cc | 1 - 4 files changed, 16 insertions(+), 15 deletions(-) diff --git a/rtc_base/BUILD.gn b/rtc_base/BUILD.gn index a35a89c043..96822ca3d3 100644 --- a/rtc_base/BUILD.gn +++ b/rtc_base/BUILD.gn @@ -654,6 +654,7 @@ rtc_static_library("rtc_numerics") { } rtc_source_set("rtc_json") { + testonly = true defines = [] sources = [ "json.cc", diff --git a/rtc_base/filerotatingstream.cc b/rtc_base/filerotatingstream.cc index 4e3aa73245..dcb18eec93 100644 --- a/rtc_base/filerotatingstream.cc +++ b/rtc_base/filerotatingstream.cc @@ -11,14 +11,15 @@ #include "rtc_base/filerotatingstream.h" #include -#include +#include #include #include "rtc_base/checks.h" #include "rtc_base/fileutils.h" #include "rtc_base/pathutils.h" +#include "rtc_base/strings/string_builder.h" -// Note: We use std::cerr for logging in the write paths of this stream to avoid +// Note: We use fprintf for logging in the write paths of this stream to avoid // infinite loops when logging. namespace rtc { @@ -149,7 +150,7 @@ StreamResult FileRotatingStream::Write(const void* data, return SR_EOS; } if (!file_stream_) { - std::cerr << "Open() must be called before Write." << std::endl; + std::fprintf(stderr, "Open() must be called before Write.\n"); return SR_ERROR; } // Write as much as will fit in to the current file. @@ -213,7 +214,7 @@ bool FileRotatingStream::Open() { std::vector matching_files = GetFilesWithPrefix(); for (auto matching_file : matching_files) { if (!Filesystem::DeleteFile(matching_file)) { - std::cerr << "Failed to delete: " << matching_file << std::endl; + std::fprintf(stderr, "Failed to delete: %s\n", matching_file.c_str()); } } return OpenCurrentFile(); @@ -225,8 +226,7 @@ bool FileRotatingStream::Open() { bool FileRotatingStream::DisableBuffering() { disable_buffering_ = true; if (!file_stream_) { - std::cerr << "Open() must be called before DisableBuffering()." - << std::endl; + std::fprintf(stderr, "Open() must be called before DisableBuffering().\n"); return false; } return file_stream_->DisableBuffering(); @@ -257,8 +257,8 @@ bool FileRotatingStream::OpenCurrentFile() { } int error = 0; if (!file_stream_->Open(file_path, mode, &error)) { - std::cerr << "Failed to open: " << file_path << "Error: " << error - << std::endl; + std::fprintf(stderr, "Failed to open: %s Error: %i\n", file_path.c_str(), + error); file_stream_.reset(); return false; } @@ -286,7 +286,7 @@ void FileRotatingStream::RotateFiles() { std::string file_to_delete = file_names_[rotation_index_]; if (Filesystem::IsFile(file_to_delete)) { if (!Filesystem::DeleteFile(file_to_delete)) { - std::cerr << "Failed to delete: " << file_to_delete << std::endl; + std::fprintf(stderr, "Failed to delete: %s\n", file_to_delete.c_str()); } } for (auto i = rotation_index_; i > 0; --i) { @@ -294,8 +294,8 @@ void FileRotatingStream::RotateFiles() { std::string unrotated_name = file_names_[i - 1]; if (Filesystem::IsFile(unrotated_name)) { if (!Filesystem::MoveFile(unrotated_name, rotated_name)) { - std::cerr << "Failed to move: " << unrotated_name << " to " - << rotated_name << std::endl; + std::fprintf(stderr, "Failed to move: %s to %s\n", + unrotated_name.c_str(), rotated_name.c_str()); } } } @@ -327,7 +327,8 @@ std::vector FileRotatingStream::GetFilesWithPrefix() const { std::string FileRotatingStream::GetFilePath(size_t index, size_t num_files) const { RTC_DCHECK_LT(index, num_files); - std::ostringstream file_name; + char buf[1024]; + rtc::SimpleStringBuilder file_name(buf); // The format will be "_%zu". We want to zero pad the index so // that it will sort nicely. size_t max_digits = ((num_files - 1) / 10) + 1; diff --git a/rtc_base/logsinks.cc b/rtc_base/logsinks.cc index 5f64f62aa3..229b54225f 100644 --- a/rtc_base/logsinks.cc +++ b/rtc_base/logsinks.cc @@ -10,7 +10,7 @@ #include "rtc_base/logsinks.h" -#include +#include #include #include "rtc_base/checks.h" @@ -37,7 +37,7 @@ FileRotatingLogSink::~FileRotatingLogSink() { void FileRotatingLogSink::OnLogMessage(const std::string& message) { if (stream_->GetState() != SS_OPEN) { - std::cerr << "Init() must be called before adding this sink." << std::endl; + std::fprintf(stderr, "Init() must be called before adding this sink.\n"); return; } stream_->WriteAll(message.c_str(), message.size(), nullptr, nullptr); diff --git a/rtc_base/macutils.cc b/rtc_base/macutils.cc index d3f2919abf..21f3f3d765 100644 --- a/rtc_base/macutils.cc +++ b/rtc_base/macutils.cc @@ -10,7 +10,6 @@ #include #include -#include #include