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 = [
":config",
"//absl/base:config",
"//absl/base:core_headers",
"//absl/base:log_severity",
"//absl/log:log_entry",
"//absl/strings",
@ -265,6 +266,7 @@ cc_library(
":config",
":test_helpers",
"//absl/base:config",
"//absl/base:core_headers",
"//absl/base:log_severity",
"//absl/log:log_entry",
"//absl/strings",

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

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

Loading…
Cancel
Save