log_component.h 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. #pragma once
  2. #include <util/generic/strbuf.h>
  3. #include <util/generic/yexception.h>
  4. namespace NYql {
  5. namespace NLog {
  6. // keep this enum in sync with simmilar enum from ydb/library/yql/utils/log/proto/logger_config.proto
  7. enum class EComponent {
  8. Default = 0,
  9. Core,
  10. CoreExecution,
  11. Sql,
  12. ProviderCommon,
  13. ProviderConfig,
  14. ProviderResult,
  15. ProviderYt,
  16. ProviderKikimr,
  17. ProviderKqp,
  18. ProviderRtmr,
  19. Performance, Perf = Performance,
  20. Net,
  21. ProviderStat,
  22. ProviderSolomon,
  23. CoreEval,
  24. CorePeepHole,
  25. ProviderDq,
  26. ProviderClickHouse,
  27. ProviderYdb,
  28. ProviderPq,
  29. ProviderS3,
  30. CoreDq,
  31. HttpGateway,
  32. ProviderGeneric,
  33. ProviderPg,
  34. ProviderPure,
  35. FastMapReduce,
  36. // <--- put other log components here
  37. MaxValue
  38. };
  39. struct EComponentHelpers {
  40. static constexpr int ToInt(EComponent component) {
  41. return static_cast<int>(component);
  42. }
  43. static constexpr EComponent FromInt(int component) {
  44. return (component >= ToInt(EComponent::Default) &&
  45. component < ToInt(EComponent::MaxValue))
  46. ? static_cast<EComponent>(component)
  47. : EComponent::Default;
  48. }
  49. static TStringBuf ToString(EComponent component) {
  50. switch (component) {
  51. case EComponent::Default: return TStringBuf("default");
  52. case EComponent::Core: return TStringBuf("core");
  53. case EComponent::CoreEval: return TStringBuf("core eval");
  54. case EComponent::CorePeepHole: return TStringBuf("core peephole");
  55. case EComponent::CoreExecution: return TStringBuf("core exec");
  56. case EComponent::Sql: return TStringBuf("sql");
  57. case EComponent::ProviderCommon: return TStringBuf("common provider");
  58. case EComponent::ProviderConfig: return TStringBuf("CONFIG");
  59. case EComponent::ProviderResult: return TStringBuf("RESULT");
  60. case EComponent::ProviderYt: return TStringBuf("YT");
  61. case EComponent::ProviderKikimr: return TStringBuf("KIKIMR");
  62. case EComponent::ProviderKqp: return TStringBuf("KQP");
  63. case EComponent::ProviderRtmr: return TStringBuf("RTMR");
  64. case EComponent::Performance: return TStringBuf("perf");
  65. case EComponent::Net: return TStringBuf("net");
  66. case EComponent::ProviderStat: return TStringBuf("STATFACE");
  67. case EComponent::ProviderSolomon: return TStringBuf("SOLOMON");
  68. case EComponent::ProviderDq: return TStringBuf("DQ");
  69. case EComponent::ProviderClickHouse: return TStringBuf("CLICKHOUSE");
  70. case EComponent::ProviderYdb: return TStringBuf("YDB");
  71. case EComponent::ProviderPq: return TStringBuf("PQ");
  72. case EComponent::ProviderS3: return TStringBuf("S3");
  73. case EComponent::CoreDq: return TStringBuf("core dq");
  74. case EComponent::HttpGateway: return TStringBuf("http gw");
  75. case EComponent::ProviderGeneric: return TStringBuf("generic");
  76. case EComponent::ProviderPg: return TStringBuf("PG");
  77. case EComponent::ProviderPure: return TStringBuf("pure");
  78. case EComponent::FastMapReduce: return TStringBuf("fast map reduce");
  79. default:
  80. ythrow yexception() << "invalid log component value: "
  81. << ToInt(component);
  82. }
  83. }
  84. static EComponent FromString(TStringBuf str) {
  85. if (str == TStringBuf("default")) return EComponent::Default;
  86. if (str == TStringBuf("core")) return EComponent::Core;
  87. if (str == TStringBuf("core eval")) return EComponent::CoreEval;
  88. if (str == TStringBuf("core peephole")) return EComponent::CorePeepHole;
  89. if (str == TStringBuf("core exec")) return EComponent::CoreExecution;
  90. if (str == TStringBuf("sql")) return EComponent::Sql;
  91. if (str == TStringBuf("common provider")) return EComponent::ProviderCommon;
  92. if (str == TStringBuf("CONFIG")) return EComponent::ProviderConfig;
  93. if (str == TStringBuf("RESULT")) return EComponent::ProviderResult;
  94. if (str == TStringBuf("YT")) return EComponent::ProviderYt;
  95. if (str == TStringBuf("KIKIMR")) return EComponent::ProviderKikimr;
  96. if (str == TStringBuf("KQP")) return EComponent::ProviderKqp;
  97. if (str == TStringBuf("RTMR")) return EComponent::ProviderRtmr;
  98. if (str == TStringBuf("perf")) return EComponent::Performance;
  99. if (str == TStringBuf("net")) return EComponent::Net;
  100. if (str == TStringBuf("STATFACE")) return EComponent::ProviderStat;
  101. if (str == TStringBuf("SOLOMON")) return EComponent::ProviderSolomon;
  102. if (str == TStringBuf("DQ")) return EComponent::ProviderDq;
  103. if (str == TStringBuf("CLICKHOUSE")) return EComponent::ProviderClickHouse;
  104. if (str == TStringBuf("YDB")) return EComponent::ProviderYdb;
  105. if (str == TStringBuf("PQ")) return EComponent::ProviderPq;
  106. if (str == TStringBuf("S3")) return EComponent::ProviderS3;
  107. if (str == TStringBuf("core dq")) return EComponent::CoreDq;
  108. if (str == TStringBuf("http gw")) return EComponent::HttpGateway;
  109. if (str == TStringBuf("generic")) return EComponent::ProviderGeneric;
  110. if (str == TStringBuf("PG")) return EComponent::ProviderPg;
  111. if (str == TStringBuf("pure")) return EComponent::ProviderPure;
  112. if (str == TStringBuf("fast map reduce")) return EComponent::FastMapReduce;
  113. ythrow yexception() << "unknown log component: '" << str << '\'';
  114. }
  115. template <typename TFunctor>
  116. static void ForEach(TFunctor&& f) {
  117. static const int minValue = ToInt(EComponent::Default);
  118. static const int maxValue = ToInt(EComponent::MaxValue);
  119. for (int c = minValue; c < maxValue; c++) {
  120. f(FromInt(c));
  121. }
  122. }
  123. };
  124. } // namespace NLog
  125. } // namespace NYql