element.h 980 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #pragma once
  2. #include "priority.h"
  3. #include <util/stream/tempbuf.h>
  4. class TLog;
  5. /*
  6. * better do not use directly
  7. */
  8. class TLogElement: public TTempBufOutput {
  9. public:
  10. TLogElement(const TLog* parent);
  11. TLogElement(const TLog* parent, ELogPriority priority);
  12. TLogElement(TLogElement&&) noexcept = default;
  13. TLogElement& operator=(TLogElement&&) noexcept = default;
  14. ~TLogElement() override;
  15. template <class T>
  16. inline TLogElement& operator<<(const T& t) {
  17. static_cast<IOutputStream&>(*this) << t;
  18. return *this;
  19. }
  20. /*
  21. * for pretty usage: logger << TLOG_ERROR << "Error description";
  22. */
  23. inline TLogElement& operator<<(ELogPriority priority) {
  24. Flush();
  25. Priority_ = priority;
  26. return *this;
  27. }
  28. ELogPriority Priority() const noexcept {
  29. return Priority_;
  30. }
  31. protected:
  32. void DoFlush() override;
  33. protected:
  34. const TLog* Parent_;
  35. ELogPriority Priority_;
  36. };