backend_creator.cpp 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. #include "backend_creator.h"
  2. #include "stream.h"
  3. #include "uninitialized_creator.h"
  4. #include <util/system/yassert.h>
  5. #include <util/stream/debug.h>
  6. #include <util/stream/output.h>
  7. THolder<TLogBackend> ILogBackendCreator::CreateLogBackend() const {
  8. try {
  9. return DoCreateLogBackend();
  10. } catch(...) {
  11. Cdbg << "Warning: " << CurrentExceptionMessage() << ". Use stderr instead." << Endl;
  12. }
  13. return MakeHolder<TStreamLogBackend>(&Cerr);
  14. }
  15. bool ILogBackendCreator::Init(const IInitContext& /*ctx*/) {
  16. return true;
  17. }
  18. NJson::TJsonValue ILogBackendCreator::AsJson() const {
  19. NJson::TJsonValue json;
  20. ToJson(json);
  21. return json;
  22. }
  23. THolder<ILogBackendCreator> ILogBackendCreator::Create(const IInitContext& ctx) {
  24. auto res = MakeHolder<TLogBackendCreatorUninitialized>();
  25. if(!res->Init(ctx)) {
  26. Cdbg << "Cannot init log backend creator";
  27. return nullptr;
  28. }
  29. return res;
  30. }
  31. TLogBackendCreatorBase::TLogBackendCreatorBase(const TString& type)
  32. : Type(type)
  33. {}
  34. void TLogBackendCreatorBase::ToJson(NJson::TJsonValue& value) const {
  35. value["LoggerType"] = Type;
  36. DoToJson(value);
  37. }