Small cleanups in logging test helpers

PiperOrigin-RevId: 486023797
Change-Id: I0b82754fd40c2d6fb451f304aaf1d795eed8d009
pull/1290/merge
Andy Getzendanner 2 years ago committed by Copybara-Service
parent 4a98f78682
commit 32e928d29c
  1. 2
      absl/log/internal/BUILD.bazel
  2. 47
      absl/log/internal/test_actions.cc
  3. 2
      absl/log/internal/test_matchers.cc

@ -230,6 +230,7 @@ cc_library(
deps = [ deps = [
":config", ":config",
"//absl/base:config", "//absl/base:config",
"//absl/base:core_headers",
"//absl/base:log_severity", "//absl/base:log_severity",
"//absl/log:log_entry", "//absl/log:log_entry",
"//absl/strings", "//absl/strings",
@ -265,6 +266,7 @@ cc_library(
":config", ":config",
":test_helpers", ":test_helpers",
"//absl/base:config", "//absl/base:config",
"//absl/base:core_headers",
"//absl/base:log_severity", "//absl/base:log_severity",
"//absl/log:log_entry", "//absl/log:log_entry",
"//absl/strings", "//absl/strings",

@ -19,9 +19,11 @@
#include <iostream> #include <iostream>
#include <string> #include <string>
#include "absl/base/attributes.h"
#include "absl/base/config.h" #include "absl/base/config.h"
#include "absl/log/internal/config.h" #include "absl/log/internal/config.h"
#include "absl/strings/escaping.h" #include "absl/strings/escaping.h"
#include "absl/strings/str_cat.h"
#include "absl/strings/string_view.h" #include "absl/strings/string_view.h"
#include "absl/time/time.h" #include "absl/time/time.h"
@ -30,37 +32,38 @@ ABSL_NAMESPACE_BEGIN
namespace log_internal { namespace log_internal {
void WriteToStderrWithFilename::operator()(const absl::LogEntry& entry) const { void WriteToStderrWithFilename::operator()(const absl::LogEntry& entry) const {
std::cerr << message << " (file: " << entry.source_filename() << ")" std::cerr << message << " (file: " << entry.source_filename() << ")\n";
<< std::endl;
} }
void WriteEntryToStderr::operator()(const absl::LogEntry& entry) const { void WriteEntryToStderr::operator()(const absl::LogEntry& entry) const {
if (!message.empty()) std::cerr << message << std::endl; if (!message.empty()) std::cerr << message << "\n";
std::cerr << "LogEntry{\n" const std::string source_filename = absl::CHexEscape(entry.source_filename());
<< " source_filename: \"" const std::string source_basename = absl::CHexEscape(entry.source_basename());
<< absl::CHexEscape(entry.source_filename()) << "\"\n" const std::string text_message = absl::CHexEscape(entry.text_message());
<< " source_basename: \"" std::cerr << "LogEntry{\n" //
<< absl::CHexEscape(entry.source_basename()) << "\"\n" << " source_filename: \"" << source_filename << "\"\n" //
<< " source_line: " << entry.source_line() << "\n" << " source_basename: \"" << source_basename << "\"\n" //
<< " prefix: " << (entry.prefix() ? "true\n" : "false\n") << " source_line: " << entry.source_line() << "\n" //
<< " log_severity: " << entry.log_severity() << "\n" << " prefix: " << (entry.prefix() ? "true\n" : "false\n") //
<< " timestamp: " << entry.timestamp() << "\n" << " log_severity: " << entry.log_severity() << "\n" //
<< " text_message: \"" << absl::CHexEscape(entry.text_message()) << " timestamp: " << entry.timestamp() << "\n" //
<< "\"\n verbosity: " << entry.verbosity() << "\n" << " text_message: \"" << text_message << "\"\n" //
<< "}" << std::endl; << " verbosity: " << entry.verbosity() << "\n" //
<< "}\n";
} }
void WriteEntryToStderr::operator()(absl::LogSeverity severity, void WriteEntryToStderr::operator()(absl::LogSeverity severity,
absl::string_view filename, absl::string_view filename,
absl::string_view log_message) const { absl::string_view log_message) const {
if (!message.empty()) std::cerr << message << std::endl; if (!message.empty()) std::cerr << message << "\n";
const std::string source_filename = absl::CHexEscape(filename);
std::cerr << "LogEntry{\n" const std::string text_message = absl::CHexEscape(log_message);
<< " source_filename: \"" << absl::CHexEscape(filename) << "\"\n" std::cerr << "LogEntry{\n" //
<< " log_severity: " << severity << "\n" << " source_filename: \"" << source_filename << "\"\n" //
<< " text_message: \"" << absl::CHexEscape(log_message) << "}" << " log_severity: " << severity << "\n" //
<< std::endl; << " text_message: \"" << text_message << "\"\n" //
<< "}\n";
} }
} // namespace log_internal } // namespace log_internal

@ -17,10 +17,12 @@
#include <sstream> #include <sstream>
#include <string> #include <string>
#include <type_traits>
#include <utility> #include <utility>
#include "gmock/gmock.h" #include "gmock/gmock.h"
#include "gtest/gtest.h" #include "gtest/gtest.h"
#include "absl/base/attributes.h"
#include "absl/base/config.h" #include "absl/base/config.h"
#include "absl/log/internal/config.h" #include "absl/log/internal/config.h"
#include "absl/log/internal/test_helpers.h" #include "absl/log/internal/test_helpers.h"

Loading…
Cancel
Save