Commit 0c048353 by Andy Getzendanner Committed by Copybara-Service

Minor formatting changes in preparation for structured logging...

PiperOrigin-RevId: 489044912
Change-Id: I1657dd60bcfa2d0fb4b889f27f4f237325b73f08
parent ae524316
......@@ -322,7 +322,6 @@ cc_test(
deps = [
":log",
":scoped_mock_log",
"//absl/log/internal:config",
"//absl/log/internal:test_matchers",
"//absl/strings",
"//absl/strings:str_format",
......
......@@ -145,7 +145,6 @@ absl_cc_library(
absl::inlined_vector
absl::examine_stack
absl::log_internal_append_truncated
absl::log_internal_config
absl::log_internal_format
absl::log_internal_globals
absl::log_internal_log_sink_set
......@@ -253,7 +252,6 @@ absl_cc_library(
DEPS
absl::config
absl::log_entry
absl::log_internal_config
absl::log_severity
absl::strings
absl::time
......@@ -295,7 +293,6 @@ absl_cc_library(
DEPS
absl::config
absl::log_entry
absl::log_internal_config
absl::log_internal_test_helpers
absl::log_severity
absl::strings
......@@ -696,7 +693,6 @@ absl_cc_test(
${ABSL_DEFAULT_LINKOPTS}
DEPS
absl::log
absl::log_internal_config
absl::log_internal_test_matchers
absl::scoped_mock_log
absl::str_format
......
......@@ -134,7 +134,6 @@ cc_library(
],
deps = [
":append_truncated",
":config",
":format",
":globals",
":log_sink_set",
......@@ -241,7 +240,6 @@ cc_library(
copts = ABSL_DEFAULT_COPTS,
linkopts = ABSL_DEFAULT_LINKOPTS,
deps = [
":config",
"//absl/base:config",
"//absl/base:core_headers",
"//absl/base:log_severity",
......@@ -276,7 +274,6 @@ cc_library(
copts = ABSL_DEFAULT_COPTS,
linkopts = ABSL_DEFAULT_LINKOPTS,
deps = [
":config",
":test_helpers",
"//absl/base:config",
"//absl/base:core_headers",
......
......@@ -42,7 +42,6 @@
#include "absl/debugging/internal/examine_stack.h"
#include "absl/log/globals.h"
#include "absl/log/internal/append_truncated.h"
#include "absl/log/internal/config.h"
#include "absl/log/internal/globals.h"
#include "absl/log/internal/log_format.h"
#include "absl/log/internal/log_sink_set.h"
......@@ -87,8 +86,8 @@ void WriteToStream(const char* data, void* os) {
// A write-only `std::streambuf` that writes into an `absl::Span<char>`.
//
// This class is responsible for writing a metadata prefix just before the first
// data are streamed in. The metadata are subject to change (cf.
// This class is responsible for writing a metadata prefix just before the
// first data are streamed in. The metadata are subject to change (cf.
// `LogMessage::AtLocation`) until then, so we wait as long as possible.
//
// This class is also responsible for reserving space for a trailing newline
......@@ -96,7 +95,8 @@ void WriteToStream(const char* data, void* os) {
// streamed in.
class LogEntryStreambuf final : public std::streambuf {
public:
explicit LogEntryStreambuf(absl::Span<char> buf, const absl::LogEntry& entry)
explicit LogEntryStreambuf(absl::Span<char> buf,
const absl::LogEntry& entry)
: buf_(buf), entry_(entry), prefix_len_(0), finalized_(false) {
// To detect when data are first written, we leave the put area null,
// override `overflow`, and check ourselves in `xsputn`.
......@@ -107,7 +107,8 @@ class LogEntryStreambuf final : public std::streambuf {
absl::Span<const char> Finalize() {
assert(!finalized_);
// If no data were ever streamed in, this is where we must write the prefix.
// If no data were ever streamed in, this is where we must write the
// prefix.
if (pbase() == nullptr) Initialize();
// Here we reclaim the two bytes we reserved.
ptrdiff_t idx = pptr() - pbase();
......@@ -140,8 +141,8 @@ class LogEntryStreambuf final : public std::streambuf {
private:
void Initialize() {
// Here we reserve two bytes in our buffer to guarantee `Finalize` space to
// add a trailing "\n\0".
// Here we reserve two bytes in our buffer to guarantee `Finalize` space
// to add a trailing "\n\0".
assert(buf_.size() >= 2);
setp(buf_.data(), buf_.data() + buf_.size() - 2);
if (entry_.prefix()) {
......@@ -157,7 +158,8 @@ class LogEntryStreambuf final : public std::streambuf {
}
size_t Append(absl::string_view data) {
absl::Span<char> remaining(pptr(), static_cast<size_t>(epptr() - pptr()));
absl::Span<char> remaining(pptr(),
static_cast<size_t>(epptr() - pptr()));
const size_t written = log_internal::AppendTruncated(data, remaining);
pbump(static_cast<int>(written));
return written;
......@@ -202,7 +204,7 @@ LogMessage::LogMessageData::LogMessageData(const char* file, int line,
absl::LogSeverity severity,
absl::Time timestamp)
: extra_sinks_only(false),
streambuf_(absl::MakeSpan(string_buf), entry) {
streambuf_(absl::MakeSpan(string_buf), entry) {
entry.full_filename_ = file;
entry.base_filename_ = Basename(file);
entry.line_ = line;
......@@ -216,8 +218,7 @@ LogMessage::LogMessageData::LogMessageData(const char* file, int line,
LogMessage::LogMessage(const char* file, int line, absl::LogSeverity severity)
: data_(
absl::make_unique<LogMessageData>(file, line, severity, absl::Now()))
,
stream_(&data_->streambuf_)
, stream_(&data_->streambuf_)
{
data_->first_fatal = false;
data_->is_perror = false;
......@@ -225,8 +226,8 @@ LogMessage::LogMessage(const char* file, int line, absl::LogSeverity severity)
// Legacy defaults for LOG's ostream:
stream_.setf(std::ios_base::showbase | std::ios_base::boolalpha);
// `fill('0')` is omitted here because its effects are very different without
// structured logging. Resolution is tracked in b/111310488.
// `fill('0')` is omitted here because its effects are very different
// without structured logging. Resolution is tracked in b/111310488.
// This logs a backtrace even if the location is subsequently changed using
// AtLocation. This quirk, and the behavior when AtLocation is called twice,
......
......@@ -37,7 +37,6 @@
#include "absl/base/config.h"
#include "absl/base/internal/errno_saver.h"
#include "absl/base/log_severity.h"
#include "absl/log/internal/config.h"
#include "absl/log/internal/nullguard.h"
#include "absl/log/log_entry.h"
#include "absl/log/log_sink.h"
......@@ -234,9 +233,10 @@ class StringifySink final {
};
// Note: the following is declared `ABSL_ATTRIBUTE_NOINLINE`
template <typename T,
typename std::enable_if<strings_internal::HasAbslStringify<T>::value,
int>::type>
template <
typename T,
typename std::enable_if<strings_internal::HasAbslStringify<T>::value,
int>::type>
LogMessage& LogMessage::operator<<(const T& v) {
StringifySink sink(*this);
// Replace with public API.
......@@ -245,9 +245,10 @@ LogMessage& LogMessage::operator<<(const T& v) {
}
// Note: the following is declared `ABSL_ATTRIBUTE_NOINLINE`
template <typename T,
typename std::enable_if<!strings_internal::HasAbslStringify<T>::value,
int>::type>
template <
typename T,
typename std::enable_if<!strings_internal::HasAbslStringify<T>::value,
int>::type>
LogMessage& LogMessage::operator<<(const T& v) {
stream_ << log_internal::NullGuard<T>().Guard(v);
return *this;
......@@ -299,7 +300,8 @@ extern template LogMessage& LogMessage::operator<<(const float& v);
extern template LogMessage& LogMessage::operator<<(const double& v);
extern template LogMessage& LogMessage::operator<<(const bool& v);
extern template LogMessage& LogMessage::operator<<(const std::string& v);
extern template LogMessage& LogMessage::operator<<(const absl::string_view& v);
extern template LogMessage& LogMessage::operator<<(
const absl::string_view& v);
// `LogMessageFatal` ensures the process will exit in failure after logging this
// message.
......
......@@ -21,7 +21,6 @@
#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"
......@@ -49,7 +48,8 @@ void WriteEntryToStderr::operator()(const absl::LogEntry& entry) const {
<< " log_severity: " << entry.log_severity() << "\n" //
<< " timestamp: " << entry.timestamp() << "\n" //
<< " text_message: \"" << text_message << "\"\n" //
<< " verbosity: " << entry.verbosity() << "\n" //
<< " verbosity: " << entry.verbosity()
<< "\n" //
<< "}\n";
}
......
......@@ -24,7 +24,6 @@
#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"
#include "absl/strings/string_view.h"
#include "absl/time/clock.h"
......
......@@ -30,7 +30,6 @@
#include "gtest/gtest.h"
#include "absl/base/config.h"
#include "absl/base/log_severity.h"
#include "absl/log/internal/config.h"
#include "absl/log/internal/test_helpers.h"
#include "absl/log/log_entry.h"
#include "absl/strings/string_view.h"
......
......@@ -26,7 +26,6 @@
#endif
#include "gmock/gmock.h"
#include "gtest/gtest.h"
#include "absl/log/internal/config.h"
#include "absl/log/internal/test_matchers.h"
#include "absl/log/log.h"
#include "absl/log/scoped_mock_log.h"
......@@ -612,8 +611,9 @@ TYPED_TEST(FloatingPointLogFormatTest, NegativeNaN) {
test_sink,
Send(AllOf(
TextMessage(MatchesOstream(comparison_stream)),
TextMessage(AnyOf(Eq("-nan"), Eq("nan"), Eq("NaN"), Eq("-nan(ind)"))),
ENCODED_MESSAGE(EqualsProto(R"pb(value { str: "-nan" })pb")))));
TextMessage(AnyOf(Eq("-nan"), Eq("nan"), Eq("NaN"),
Eq("-nan(ind)"))), ENCODED_MESSAGE(EqualsProto(R"pb(value { str:
"-nan" })pb")))));
test_sink.StartCapturingLogs();
LOG(INFO) << value;
......@@ -1642,19 +1642,20 @@ TEST(ManipulatorLogFormatTest, IOManipsDoNotAffectAbslStringify) {
// Tests that verify the behavior when more data are streamed into a `LOG`
// statement than fit in the buffer.
// Structured logging scenario is tested in other unit tests since the output is
// significantly different.
// Structured logging scenario is tested in other unit tests since the output
// is significantly different.
TEST(OverflowTest, TruncatesStrings) {
absl::ScopedMockLog test_sink(absl::MockLogDefault::kDisallowUnexpected);
// This message is too long and should be truncated to some unspecified size
// no greater than the buffer size but not too much less either. It should be
// truncated rather than discarded.
// This message is too long and should be truncated to some unspecified
// size no greater than the buffer size but not too much less either. It
// should be truncated rather than discarded.
constexpr size_t buffer_size = 15000;
EXPECT_CALL(test_sink,
Send(TextMessage(
AllOf(SizeIs(AllOf(Ge(buffer_size - 256), Le(buffer_size))),
AllOf(SizeIs(AllOf(Ge(buffer_size - 256),
Le(buffer_size))),
Each(Eq('x'))))));
test_sink.StartCapturingLogs();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment