filter.h 699 B

1234567891011121314151617181920212223242526272829303132
  1. #pragma once
  2. #include "priority.h"
  3. #include "record.h"
  4. #include "backend.h"
  5. #include <util/generic/ptr.h>
  6. class TFilteredLogBackend: public TLogBackend {
  7. THolder<TLogBackend> Backend;
  8. ELogPriority Level;
  9. public:
  10. TFilteredLogBackend(THolder<TLogBackend>&& t, ELogPriority level = LOG_MAX_PRIORITY) noexcept
  11. : Backend(std::move(t))
  12. , Level(level)
  13. {
  14. }
  15. ELogPriority FiltrationLevel() const override {
  16. return Level;
  17. }
  18. void ReopenLog() override {
  19. Backend->ReopenLog();
  20. }
  21. void WriteData(const TLogRecord& rec) override {
  22. if (rec.Priority <= (ELogPriority)Level) {
  23. Backend->WriteData(rec);
  24. }
  25. }
  26. };