backend_creator.cpp 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. #include "backend_creator.h"
  2. #include <library/cpp/logger/global/global.h>
  3. namespace NUnifiedAgent {
  4. TLogBackendCreator::TLogBackendCreator()
  5. : TLogBackendCreatorBase("unified_agent")
  6. {}
  7. bool TLogBackendCreator::Init(const IInitContext& ctx) {
  8. if(TString socket = ctx.GetOrElse("Uri", TString())) {
  9. ClientParams = MakeHolder<TClientParameters>(socket);
  10. } else {
  11. Cdbg << "Uri not set for unified_agent log backend" << Endl;
  12. return false;
  13. }
  14. TString secretKey;
  15. ctx.GetValue("SharedSecretKey", secretKey);
  16. if (secretKey) {
  17. ClientParams->SharedSecretKey = secretKey;
  18. }
  19. ctx.GetValue("MaxInflightBytes", ClientParams->MaxInflightBytes);
  20. ctx.GetValue("GrpcSendDelay", ClientParams->GrpcSendDelay);
  21. size_t rateLimit;
  22. if (ctx.GetValue("LogRateLimit", rateLimit)) {
  23. ClientParams->LogRateLimitBytes = rateLimit;
  24. }
  25. ctx.GetValue("GrpcReconnectDelay", ClientParams->GrpcReconnectDelay);
  26. ctx.GetValue("GrpcMaxMessageSize", ClientParams->GrpcMaxMessageSize);
  27. const auto ownLogger = ctx.GetChildren("OwnLogger");
  28. if (!ownLogger.empty() && ownLogger.front()->GetOrElse("LoggerType", TString()) != "global") {
  29. OwnLogger = ILogBackendCreator::Create(*ownLogger.front());
  30. TLog log;
  31. log.ResetBackend(OwnLogger->CreateLogBackend());
  32. ClientParams->SetLog(log);
  33. }
  34. return true;
  35. }
  36. void TLogBackendCreator::DoToJson(NJson::TJsonValue& value) const {
  37. value["Uri"] = ClientParams->Uri;
  38. if (ClientParams->SharedSecretKey) {
  39. value["SharedSecretKey"] = *ClientParams->SharedSecretKey;
  40. }
  41. value["MaxInflightBytes"] = ClientParams->MaxInflightBytes;
  42. value["GrpcSendDelay"] = ClientParams->GrpcSendDelay.ToString();
  43. if (ClientParams->LogRateLimitBytes) {
  44. value["LogRateLimit"] = *ClientParams->LogRateLimitBytes;
  45. }
  46. value["GrpcReconnectDelay"] = ClientParams->GrpcReconnectDelay.ToString();
  47. value["GrpcMaxMessageSize"] = ClientParams->GrpcMaxMessageSize;
  48. if (OwnLogger) {
  49. OwnLogger->ToJson(value["OwnLogger"].AppendValue(NJson::JSON_MAP));
  50. }
  51. }
  52. THolder<TLogBackend> TLogBackendCreator::DoCreateLogBackend() const {
  53. return MakeLogBackend(*ClientParams);
  54. }
  55. }