uninitialized_creator.cpp 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. #include "uninitialized_creator.h"
  2. #include "filter_creator.h"
  3. #include "thread_creator.h"
  4. #include "file_creator.h"
  5. #include "null_creator.h"
  6. #include <util/string/cast.h>
  7. THolder<TLogBackend> TLogBackendCreatorUninitialized::DoCreateLogBackend() const {
  8. return Slave->CreateLogBackend();
  9. }
  10. void TLogBackendCreatorUninitialized::InitCustom(const TString& type, ELogPriority priority, bool threaded) {
  11. if (!type) {
  12. Slave = MakeHolder<TNullLogBackendCreator>();
  13. } else if (TFactory::Has(type)) {
  14. Slave = TFactory::MakeHolder(type);
  15. } else {
  16. Slave = MakeHolder<TFileLogBackendCreator>(type);
  17. }
  18. if (threaded) {
  19. Slave = MakeHolder<TOwningThreadedLogBackendCreator>(std::move(Slave));
  20. }
  21. if (priority != LOG_MAX_PRIORITY) {
  22. Slave = MakeHolder<TFilteredBackendCreator>(std::move(Slave), priority);
  23. }
  24. }
  25. bool TLogBackendCreatorUninitialized::Init(const IInitContext& ctx) {
  26. auto type = ctx.GetOrElse("LoggerType", TString());
  27. bool threaded = ctx.GetOrElse("Threaded", false);
  28. ELogPriority priority = LOG_MAX_PRIORITY;
  29. TString prStr;
  30. if (ctx.GetValue("LogLevel", prStr)) {
  31. if (!TryFromString(prStr, priority)) {
  32. priority = (ELogPriority)FromString<int>(prStr);
  33. }
  34. }
  35. InitCustom(type, priority, threaded);
  36. return Slave->Init(ctx);
  37. }
  38. void TLogBackendCreatorUninitialized::ToJson(NJson::TJsonValue& value) const {
  39. Y_ABORT_UNLESS(Slave, "Serialization off uninitialized LogBackendCreator");
  40. Slave->ToJson(value);
  41. }
  42. ILogBackendCreator::TFactory::TRegistrator<TLogBackendCreatorUninitialized> TLogBackendCreatorUninitialized::Registrar("");