chromium/third_party/abseil-cpp/absl/log/internal/log_message.cc

//
// Copyright 2022 The Abseil Authors.
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//      https://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "absl/log/internal/log_message.h"

#include <stddef.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>

#ifndef _WIN32
#include <unistd.h>
#endif

#include <algorithm>
#include <array>
#include <atomic>
#include <ios>
#include <memory>
#include <ostream>
#include <string>
#include <tuple>

#include "absl/base/attributes.h"
#include "absl/base/config.h"
#include "absl/base/internal/raw_logging.h"
#include "absl/base/internal/strerror.h"
#include "absl/base/internal/sysinfo.h"
#include "absl/base/log_severity.h"
#include "absl/container/inlined_vector.h"
#include "absl/debugging/internal/examine_stack.h"
#include "absl/log/globals.h"
#include "absl/log/internal/append_truncated.h"
#include "absl/log/internal/globals.h"
#include "absl/log/internal/log_format.h"
#include "absl/log/internal/log_sink_set.h"
#include "absl/log/internal/proto.h"
#include "absl/log/log_entry.h"
#include "absl/log/log_sink.h"
#include "absl/log/log_sink_registry.h"
#include "absl/memory/memory.h"
#include "absl/strings/string_view.h"
#include "absl/time/clock.h"
#include "absl/time/time.h"
#include "absl/types/span.h"

extern "C" ABSL_ATTRIBUTE_WEAK void ABSL_INTERNAL_C_SYMBOL(
    AbslInternalOnFatalLogMessage)(const absl::LogEntry&) {}

namespace absl {
ABSL_NAMESPACE_BEGIN
namespace log_internal {

namespace {
// message `logging.proto.Event`
enum EventTag : uint8_t {};

// message `logging.proto.Value`
enum ValueTag : uint8_t {};

// Decodes a `logging.proto.Value` from `buf` and writes a string representation
// into `dst`.  The string representation will be truncated if `dst` is not
// large enough to hold it.  Returns false if `dst` has size zero or one (i.e.
// sufficient only for a nul-terminator) and no decoded data could be written.
// This function may or may not write a nul-terminator into `dst`, and it may or
// may not truncate the data it writes in order to do make space for that nul
// terminator.  In any case, `dst` will be advanced to point at the byte where
// subsequent writes should begin.
bool PrintValue(absl::Span<char>& dst, absl::Span<const char> buf) {}

// See `logging.proto.Severity`
int32_t ProtoSeverity(absl::LogSeverity severity, int verbose_level) {}

absl::string_view Basename(absl::string_view filepath) {}

void WriteToString(const char* data, void* str) {}
void WriteToStream(const char* data, void* os) {}
}  // namespace

struct LogMessage::LogMessageData final {};

LogMessage::LogMessageData::LogMessageData(const char* file, int line,
                                           absl::LogSeverity severity,
                                           absl::Time timestamp)
    :{}

void LogMessage::LogMessageData::InitializeEncodingAndFormat() {}

void LogMessage::LogMessageData::FinalizeEncodingAndFormat() {}

LogMessage::LogMessage(const char* file, int line, absl::LogSeverity severity)
    :{}

LogMessage::LogMessage(const char* file, int line, InfoTag)
    :{}
LogMessage::LogMessage(const char* file, int line, WarningTag)
    :{}
LogMessage::LogMessage(const char* file, int line, ErrorTag)
    :{}

LogMessage::~LogMessage() {}

LogMessage& LogMessage::AtLocation(absl::string_view file, int line) {}

LogMessage& LogMessage::NoPrefix() {}

LogMessage& LogMessage::WithVerbosity(int verbose_level) {}

LogMessage& LogMessage::WithTimestamp(absl::Time timestamp) {}

LogMessage& LogMessage::WithThreadID(absl::LogEntry::tid_t tid) {}

LogMessage& LogMessage::WithMetadataFrom(const absl::LogEntry& entry) {}

LogMessage& LogMessage::WithPerror() {}

LogMessage& LogMessage::ToSinkAlso(absl::LogSink* sink) {}

LogMessage& LogMessage::ToSinkOnly(absl::LogSink* sink) {}

#ifdef __ELF__
extern "C" void __gcov_dump() ABSL_ATTRIBUTE_WEAK;
extern "C" void __gcov_flush() ABSL_ATTRIBUTE_WEAK;
#endif

void LogMessage::FailWithoutStackTrace() {}

void LogMessage::FailQuietly() {}

LogMessage& LogMessage::operator<<(const std::string& v) {}

LogMessage& LogMessage::operator<<(absl::string_view v) {}
LogMessage& LogMessage::operator<<(std::ostream& (*m)(std::ostream& os)) {}
LogMessage& LogMessage::operator<<(std::ios_base& (*m)(std::ios_base& os)) {}
template LogMessage& LogMessage::operator<<(const char& v);
template LogMessage& LogMessage::operator<<(const signed char& v);
template LogMessage& LogMessage::operator<<(const unsigned char& v);
template LogMessage& LogMessage::operator<<(const short& v);           // NOLINT
template LogMessage& LogMessage::operator<<(const unsigned short& v);  // NOLINT
template LogMessage& LogMessage::operator<<(const int& v);
template LogMessage& LogMessage::operator<<(const unsigned int& v);
template LogMessage& LogMessage::operator<<(const long& v);           // NOLINT
template LogMessage& LogMessage::operator<<(const unsigned long& v);  // NOLINT
template LogMessage& LogMessage::operator<<(const long long& v);      // NOLINT
template LogMessage& LogMessage::operator<<(
    const unsigned long long& v);  // NOLINT
template LogMessage& LogMessage::operator<<(void* const& v);
template LogMessage& LogMessage::operator<<(const void* const& v);
template LogMessage& LogMessage::operator<<(const float& v);
template LogMessage& LogMessage::operator<<(const double& v);
template LogMessage& LogMessage::operator<<(const bool& v);

void LogMessage::Flush() {}

void LogMessage::SetFailQuietly() {}

LogMessage::OstreamView::OstreamView(LogMessageData& message_data)
    :{}

LogMessage::OstreamView::~OstreamView() {}

std::ostream& LogMessage::OstreamView::stream() {}

bool LogMessage::IsFatal() const {}

void LogMessage::PrepareToDie() {}

void LogMessage::Die() {}

void LogMessage::SendToLog() {}

void LogMessage::LogBacktraceIfNeeded() {}

// Encodes into `data_->encoded_remaining()` a partial `logging.proto.Event`
// containing the specified string data using a `Value` field appropriate to
// `str_type`.  Truncates `str` if necessary, but emits nothing and marks the
// buffer full if  even the field headers do not fit.
template <LogMessage::StringType str_type>
void LogMessage::CopyToEncodedBuffer(absl::string_view str) {}
template void LogMessage::CopyToEncodedBuffer<LogMessage::StringType::kLiteral>(
    absl::string_view str);
template void LogMessage::CopyToEncodedBuffer<
    LogMessage::StringType::kNotLiteral>(absl::string_view str);
template <LogMessage::StringType str_type>
void LogMessage::CopyToEncodedBuffer(char ch, size_t num) {}
template void LogMessage::CopyToEncodedBuffer<LogMessage::StringType::kLiteral>(
    char ch, size_t num);
template void LogMessage::CopyToEncodedBuffer<
    LogMessage::StringType::kNotLiteral>(char ch, size_t num);

// We intentionally don't return from these destructors. Disable MSVC's warning
// about the destructor never returning as we do so intentionally here.
#if defined(_MSC_VER) && !defined(__clang__)
#pragma warning(push)
#pragma warning(disable : 4722)
#endif

LogMessageFatal::LogMessageFatal(const char* file, int line)
    :{}

LogMessageFatal::LogMessageFatal(const char* file, int line,
                                 absl::string_view failure_msg)
    :{}

LogMessageFatal::~LogMessageFatal() {}

LogMessageDebugFatal::LogMessageDebugFatal(const char* file, int line)
    :{}

LogMessageDebugFatal::~LogMessageDebugFatal() {}

LogMessageQuietlyDebugFatal::LogMessageQuietlyDebugFatal(const char* file,
                                                         int line)
    :{}

LogMessageQuietlyDebugFatal::~LogMessageQuietlyDebugFatal() {}

LogMessageQuietlyFatal::LogMessageQuietlyFatal(const char* file, int line)
    :{}

LogMessageQuietlyFatal::LogMessageQuietlyFatal(const char* file, int line,
                                               absl::string_view failure_msg)
    :{}

LogMessageQuietlyFatal::~LogMessageQuietlyFatal() {}
#if defined(_MSC_VER) && !defined(__clang__)
#pragma warning(pop)
#endif

}  // namespace log_internal

ABSL_NAMESPACE_END
}  // namespace absl