File indexing completed on 2024-11-15 09:01:05
0001
0002
0003
0004
0005
0006
0007
0008
0009
0010
0011
0012
0013
0014
0015
0016
0017
0018
0019
0020
0021
0022
0023 #ifndef ABSL_LOG_INTERNAL_NULLSTREAM_H_
0024 #define ABSL_LOG_INTERNAL_NULLSTREAM_H_
0025
0026 #ifdef _WIN32
0027 #include <cstdlib>
0028 #else
0029 #include <unistd.h>
0030 #endif
0031 #include <ios>
0032 #include <ostream>
0033
0034 #include "absl/base/attributes.h"
0035 #include "absl/base/config.h"
0036 #include "absl/base/log_severity.h"
0037 #include "absl/strings/string_view.h"
0038
0039 namespace absl {
0040 ABSL_NAMESPACE_BEGIN
0041 namespace log_internal {
0042
0043
0044
0045
0046
0047 class NullStream {
0048 public:
0049 NullStream& AtLocation(absl::string_view, int) { return *this; }
0050 template <typename SourceLocationType>
0051 NullStream& AtLocation(SourceLocationType) {
0052 return *this;
0053 }
0054 NullStream& NoPrefix() { return *this; }
0055 NullStream& WithVerbosity(int) { return *this; }
0056 template <typename TimeType>
0057 NullStream& WithTimestamp(TimeType) {
0058 return *this;
0059 }
0060 template <typename Tid>
0061 NullStream& WithThreadID(Tid) {
0062 return *this;
0063 }
0064 template <typename LogEntryType>
0065 NullStream& WithMetadataFrom(const LogEntryType&) {
0066 return *this;
0067 }
0068 NullStream& WithPerror() { return *this; }
0069 template <typename LogSinkType>
0070 NullStream& ToSinkAlso(LogSinkType*) {
0071 return *this;
0072 }
0073 template <typename LogSinkType>
0074 NullStream& ToSinkOnly(LogSinkType*) {
0075 return *this;
0076 }
0077 template <typename LogSinkType>
0078 NullStream& OutputToSink(LogSinkType*, bool) {
0079 return *this;
0080 }
0081 NullStream& InternalStream() { return *this; }
0082 };
0083 template <typename T>
0084 inline NullStream& operator<<(NullStream& str, const T&) {
0085 return str;
0086 }
0087 inline NullStream& operator<<(NullStream& str,
0088 std::ostream& (*)(std::ostream& os)) {
0089 return str;
0090 }
0091 inline NullStream& operator<<(NullStream& str,
0092 std::ios_base& (*)(std::ios_base& os)) {
0093 return str;
0094 }
0095
0096
0097
0098
0099
0100 class NullStreamMaybeFatal final : public NullStream {
0101 public:
0102 explicit NullStreamMaybeFatal(absl::LogSeverity severity)
0103 : fatal_(severity == absl::LogSeverity::kFatal) {}
0104 ~NullStreamMaybeFatal() {
0105 if (fatal_) {
0106 _exit(1);
0107 }
0108 }
0109
0110 private:
0111 bool fatal_;
0112 };
0113
0114
0115
0116
0117 class NullStreamFatal final : public NullStream {
0118 public:
0119 NullStreamFatal() = default;
0120
0121
0122 #if defined(_MSC_VER) && !defined(__clang__)
0123 #pragma warning(push)
0124 #pragma warning(disable : 4722)
0125 #endif
0126 ABSL_ATTRIBUTE_NORETURN ~NullStreamFatal() { _exit(1); }
0127 #if defined(_MSC_VER) && !defined(__clang__)
0128 #pragma warning(pop)
0129 #endif
0130 };
0131
0132 }
0133 ABSL_NAMESPACE_END
0134 }
0135
0136 #endif