#include "stream_log_manager.h" #include #include #include #include namespace NYT::NLogging { //////////////////////////////////////////////////////////////////////////////// class TStreamLogManager : public ILogManager { public: explicit TStreamLogManager(IOutputStream* output) : Output_(output) { } void RegisterStaticAnchor( TLoggingAnchor* anchor, ::TSourceLocation /*sourceLocation*/, TStringBuf /*anchorMessage*/) override { anchor->Registered = true; } virtual void UpdateAnchor(TLoggingAnchor* anchor) override { anchor->Enabled = true; } virtual void Enqueue(TLogEvent&& event) override { Buffer_.Reset(); EventFormatter_.Format(&Buffer_, event); *Output_ << Buffer_.GetBuffer() << Endl; } virtual const TLoggingCategory* GetCategory(TStringBuf categoryName) override { if (!categoryName) { return nullptr; } auto guard = Guard(SpinLock_); auto it = NameToCategory_.find(categoryName); if (it == NameToCategory_.end()) { auto category = std::make_unique(); category->Name = categoryName; category->ActualVersion = &Version_; category->CurrentVersion = Version_.load(); it = NameToCategory_.emplace(categoryName, std::move(category)).first; } return it->second.get(); } virtual void UpdateCategory(TLoggingCategory* /*category*/) override { } virtual bool GetAbortOnAlert() const override { return false; } private: IOutputStream* const Output_; NThreading::TForkAwareSpinLock SpinLock_; THashMap> NameToCategory_; std::atomic Version_ = 1; TPlainTextEventFormatter EventFormatter_{/*enableSourceLocation*/ false}; TRawFormatter Buffer_; }; std::unique_ptr CreateStreamLogManager(IOutputStream* output) { return std::make_unique(output); } //////////////////////////////////////////////////////////////////////////////// } // namespace NYT::NLogging