diff options
author | Anton Samokhvalov <pg83@yandex.ru> | 2022-02-10 16:45:15 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:45:15 +0300 |
commit | 72cb13b4aff9bc9cf22e49251bc8fd143f82538f (patch) | |
tree | da2c34829458c7d4e74bdfbdf85dff449e9e7fb8 /library/cpp/logger/file.cpp | |
parent | 778e51ba091dc39e7b7fcab2b9cf4dbedfb6f2b5 (diff) | |
download | ydb-72cb13b4aff9bc9cf22e49251bc8fd143f82538f.tar.gz |
Restoring authorship annotation for Anton Samokhvalov <pg83@yandex.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/logger/file.cpp')
-rw-r--r-- | library/cpp/logger/file.cpp | 98 |
1 files changed, 49 insertions, 49 deletions
diff --git a/library/cpp/logger/file.cpp b/library/cpp/logger/file.cpp index 15a4946eda..c5ecd5550c 100644 --- a/library/cpp/logger/file.cpp +++ b/library/cpp/logger/file.cpp @@ -1,59 +1,59 @@ -#include "file.h" -#include "record.h" - -#include <util/system/file.h> -#include <util/system/rwlock.h> +#include "file.h" +#include "record.h" + +#include <util/system/file.h> +#include <util/system/rwlock.h> #include <util/generic/string.h> - -/* - * file log - */ + +/* + * file log + */ class TFileLogBackend::TImpl { -public: +public: inline TImpl(const TString& path) - : File_(OpenFile(path)) - { - } - - inline void WriteData(const TLogRecord& rec) { - //many writes are thread-safe - TReadGuard guard(Lock_); - - File_.Write(rec.Data, rec.Len); - } - - inline void ReopenLog() { - //but log rotate not thread-safe - TWriteGuard guard(Lock_); - - File_.LinkTo(OpenFile(File_.GetName())); - } - -private: + : File_(OpenFile(path)) + { + } + + inline void WriteData(const TLogRecord& rec) { + //many writes are thread-safe + TReadGuard guard(Lock_); + + File_.Write(rec.Data, rec.Len); + } + + inline void ReopenLog() { + //but log rotate not thread-safe + TWriteGuard guard(Lock_); + + File_.LinkTo(OpenFile(File_.GetName())); + } + +private: static inline TFile OpenFile(const TString& path) { - return TFile(path, OpenAlways | WrOnly | ForAppend | Seq | NoReuse); - } - -private: - TRWMutex Lock_; - TFile File_; -}; - + return TFile(path, OpenAlways | WrOnly | ForAppend | Seq | NoReuse); + } + +private: + TRWMutex Lock_; + TFile File_; +}; + TFileLogBackend::TFileLogBackend(const TString& path) - : Impl_(new TImpl(path)) -{ -} - + : Impl_(new TImpl(path)) +{ +} + TFileLogBackend::~TFileLogBackend() { -} - -void TFileLogBackend::WriteData(const TLogRecord& rec) { - Impl_->WriteData(rec); -} - -void TFileLogBackend::ReopenLog() { +} + +void TFileLogBackend::WriteData(const TLogRecord& rec) { + Impl_->WriteData(rec); +} + +void TFileLogBackend::ReopenLog() { TAtomicSharedPtr<TImpl> copy = Impl_; if (copy) { copy->ReopenLog(); } -} +} |