log_severity.cc 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // Copyright 2017 The Abseil Authors.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // https://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. #include "absl/base/log_severity.h"
  15. #include <ostream>
  16. #include "absl/base/attributes.h"
  17. #include "absl/base/config.h"
  18. namespace absl {
  19. ABSL_NAMESPACE_BEGIN
  20. std::ostream& operator<<(std::ostream& os, absl::LogSeverity s) {
  21. if (s == absl::NormalizeLogSeverity(s)) return os << absl::LogSeverityName(s);
  22. return os << "absl::LogSeverity(" << static_cast<int>(s) << ")";
  23. }
  24. std::ostream& operator<<(std::ostream& os, absl::LogSeverityAtLeast s) {
  25. switch (s) {
  26. case absl::LogSeverityAtLeast::kInfo:
  27. case absl::LogSeverityAtLeast::kWarning:
  28. case absl::LogSeverityAtLeast::kError:
  29. case absl::LogSeverityAtLeast::kFatal:
  30. return os << ">=" << static_cast<absl::LogSeverity>(s);
  31. case absl::LogSeverityAtLeast::kInfinity:
  32. return os << "INFINITY";
  33. }
  34. return os;
  35. }
  36. std::ostream& operator<<(std::ostream& os, absl::LogSeverityAtMost s) {
  37. switch (s) {
  38. case absl::LogSeverityAtMost::kInfo:
  39. case absl::LogSeverityAtMost::kWarning:
  40. case absl::LogSeverityAtMost::kError:
  41. case absl::LogSeverityAtMost::kFatal:
  42. return os << "<=" << static_cast<absl::LogSeverity>(s);
  43. case absl::LogSeverityAtMost::kNegativeInfinity:
  44. return os << "NEGATIVE_INFINITY";
  45. }
  46. return os;
  47. }
  48. ABSL_NAMESPACE_END
  49. } // namespace absl