rty_formater.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. #pragma once
  2. #include "common.h"
  3. namespace NMemInfo {
  4. struct TMemInfo;
  5. }
  6. class ILoggerFormatter {
  7. public:
  8. virtual ~ILoggerFormatter() = default;
  9. virtual void Format(const TLogRecordContext&, TLogElement&) const = 0;
  10. };
  11. ILoggerFormatter* CreateRtyLoggerFormatter();
  12. namespace NLoggingImpl {
  13. class TLocalTimeS {
  14. public:
  15. TLocalTimeS(TInstant instant = TInstant::Now())
  16. : Instant(instant)
  17. {
  18. }
  19. TInstant GetInstant() const {
  20. return Instant;
  21. }
  22. operator TString() const;
  23. TString operator+(TStringBuf right) const;
  24. private:
  25. TInstant Instant;
  26. };
  27. IOutputStream& operator<<(IOutputStream& out, TLocalTimeS localTimeS);
  28. inline TLocalTimeS GetLocalTimeS() {
  29. return TLocalTimeS();
  30. }
  31. TString GetSystemResources();
  32. TString PrintSystemResources(const NMemInfo::TMemInfo& info);
  33. struct TLoggerFormatterTraits {
  34. static ILoggerFormatter* CreateDefault() {
  35. return CreateRtyLoggerFormatter();
  36. }
  37. };
  38. }
  39. class TLoggerFormatterOperator : public NLoggingImpl::TOperatorBase<ILoggerFormatter, NLoggingImpl::TLoggerFormatterTraits> {
  40. };
  41. struct TRTYMessageFormater {
  42. static bool CheckLoggingContext(TLog& logger, const TLogRecordContext& context);
  43. static TSimpleSharedPtr<TLogElement> StartRecord(TLog& logger, const TLogRecordContext& context, TSimpleSharedPtr<TLogElement> earlier);
  44. };
  45. using TRTYLogPreprocessor = TLogRecordPreprocessor<TLogFilter, TRTYMessageFormater>;