logger.cpp 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include "logger.h"
  2. namespace NGrpc {
  3. namespace {
  4. static_assert(
  5. ui16(TLOG_EMERG) == ui16(NActors::NLog::PRI_EMERG) &&
  6. ui16(TLOG_DEBUG) == ui16(NActors::NLog::PRI_DEBUG),
  7. "log levels in the library/log and library/cpp/actors don't match");
  8. class TActorSystemLogger final: public TLogger {
  9. public:
  10. TActorSystemLogger(NActors::TActorSystem& as, NActors::NLog::EComponent component) noexcept
  11. : ActorSystem_{as}
  12. , Component_{component}
  13. {
  14. }
  15. protected:
  16. bool DoIsEnabled(ELogPriority p) const noexcept override {
  17. const auto* settings = static_cast<::NActors::NLog::TSettings*>(ActorSystem_.LoggerSettings());
  18. const auto priority = static_cast<::NActors::NLog::EPriority>(p);
  19. return settings && settings->Satisfies(priority, Component_, 0);
  20. }
  21. void DoWrite(ELogPriority p, const char* format, va_list args) noexcept override {
  22. Y_DEBUG_ABORT_UNLESS(DoIsEnabled(p));
  23. const auto priority = static_cast<::NActors::NLog::EPriority>(p);
  24. ::NActors::MemLogAdapter(ActorSystem_, priority, Component_, format, args);
  25. }
  26. private:
  27. NActors::TActorSystem& ActorSystem_;
  28. NActors::NLog::EComponent Component_;
  29. };
  30. } // namespace
  31. TLoggerPtr CreateActorSystemLogger(NActors::TActorSystem& as, NActors::NLog::EComponent component) {
  32. return MakeIntrusive<TActorSystemLogger>(as, component);
  33. }
  34. } // namespace NGrpc