| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
|
|
| #ifndef ABSL_LOG_INTERNAL_NULLSTREAM_H_ |
| #define ABSL_LOG_INTERNAL_NULLSTREAM_H_ |
|
|
| #ifdef _WIN32 |
| #include <cstdlib> |
| #else |
| #include <unistd.h> |
| #endif |
| #include <ios> |
| #include <ostream> |
|
|
| #include "absl/base/attributes.h" |
| #include "absl/base/config.h" |
| #include "absl/base/log_severity.h" |
| #include "absl/strings/string_view.h" |
|
|
| namespace absl { |
| ABSL_NAMESPACE_BEGIN |
| namespace log_internal { |
|
|
| |
| |
| |
| |
| class NullStream { |
| public: |
| NullStream& AtLocation(absl::string_view, int) { return *this; } |
| template <typename SourceLocationType> |
| NullStream& AtLocation(SourceLocationType) { |
| return *this; |
| } |
| NullStream& NoPrefix() { return *this; } |
| NullStream& WithVerbosity(int) { return *this; } |
| template <typename TimeType> |
| NullStream& WithTimestamp(TimeType) { |
| return *this; |
| } |
| template <typename Tid> |
| NullStream& WithThreadID(Tid) { |
| return *this; |
| } |
| template <typename LogEntryType> |
| NullStream& WithMetadataFrom(const LogEntryType&) { |
| return *this; |
| } |
| NullStream& WithPerror() { return *this; } |
| template <typename LogSinkType> |
| NullStream& ToSinkAlso(LogSinkType*) { |
| return *this; |
| } |
| template <typename LogSinkType> |
| NullStream& ToSinkOnly(LogSinkType*) { |
| return *this; |
| } |
| template <typename LogSinkType> |
| NullStream& OutputToSink(LogSinkType*, bool) { |
| return *this; |
| } |
| NullStream& InternalStream() { return *this; } |
| }; |
| template <typename T> |
| inline NullStream& operator<<(NullStream& str, const T&) { |
| return str; |
| } |
| inline NullStream& operator<<(NullStream& str, |
| std::ostream& (*)(std::ostream& os)) { |
| return str; |
| } |
| inline NullStream& operator<<(NullStream& str, |
| std::ios_base& (*)(std::ios_base& os)) { |
| return str; |
| } |
|
|
| |
| |
| |
| |
| class NullStreamMaybeFatal final : public NullStream { |
| public: |
| explicit NullStreamMaybeFatal(absl::LogSeverity severity) |
| : fatal_(severity == absl::LogSeverity::kFatal) {} |
| ~NullStreamMaybeFatal() { |
| if (fatal_) { |
| _exit(1); |
| } |
| } |
|
|
| private: |
| bool fatal_; |
| }; |
|
|
| |
| |
| |
| class NullStreamFatal final : public NullStream { |
| public: |
| NullStreamFatal() = default; |
| |
| |
| #if defined(_MSC_VER) && !defined(__clang__) |
| #pragma warning(push) |
| #pragma warning(disable : 4722) |
| #endif |
| ABSL_ATTRIBUTE_NORETURN ~NullStreamFatal() { _exit(1); } |
| #if defined(_MSC_VER) && !defined(__clang__) |
| #pragma warning(pop) |
| #endif |
| }; |
|
|
| } |
| ABSL_NAMESPACE_END |
| } |
|
|
| #endif |
|
|