diff options
author | danibw <danibw@yandex-team.ru> | 2022-02-10 16:50:12 +0300 |
---|---|---|
committer | Daniil Cherednik <dcherednik@yandex-team.ru> | 2022-02-10 16:50:12 +0300 |
commit | e8fdd1e6c0645bf1702aaf85cc7460dbd09977cb (patch) | |
tree | d96a47e62e16b199f4ffbf41f6848e9fad7dfa21 /library/cpp/logger/rotating_file.cpp | |
parent | df6eb5b163c763cd9633a4850cfae72f8d742996 (diff) | |
download | ydb-e8fdd1e6c0645bf1702aaf85cc7460dbd09977cb.tar.gz |
Restoring authorship annotation for <danibw@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/logger/rotating_file.cpp')
-rw-r--r-- | library/cpp/logger/rotating_file.cpp | 64 |
1 files changed, 32 insertions, 32 deletions
diff --git a/library/cpp/logger/rotating_file.cpp b/library/cpp/logger/rotating_file.cpp index a62f48f25db..3391d260025 100644 --- a/library/cpp/logger/rotating_file.cpp +++ b/library/cpp/logger/rotating_file.cpp @@ -2,7 +2,7 @@ #include "file.h" #include "record.h" -#include <util/string/builder.h> +#include <util/string/builder.h> #include <util/system/fstat.h> #include <util/system/rwlock.h> #include <util/system/fs.h> @@ -11,36 +11,36 @@ /* * rotating file log - * if Size_ > MaxSizeBytes - * Path.(N-1) -> Path.N - * Path.(N-2) -> Path.(N-1) - * ... - * Path.1 -> Path.2 - * Path -> Path.1 + * if Size_ > MaxSizeBytes + * Path.(N-1) -> Path.N + * Path.(N-2) -> Path.(N-1) + * ... + * Path.1 -> Path.2 + * Path -> Path.1 */ class TRotatingFileLogBackend::TImpl { public: - inline TImpl(const TString& path, const ui64 maxSizeBytes, const ui32 rotatedFilesCount) - : Log_(path) - , Path_(path) - , MaxSizeBytes_(maxSizeBytes) - , Size_(TFileStat(Path_).Size) - , RotatedFilesCount_(rotatedFilesCount) - { - Y_ENSURE(RotatedFilesCount_ != 0); - } - + inline TImpl(const TString& path, const ui64 maxSizeBytes, const ui32 rotatedFilesCount) + : Log_(path) + , Path_(path) + , MaxSizeBytes_(maxSizeBytes) + , Size_(TFileStat(Path_).Size) + , RotatedFilesCount_(rotatedFilesCount) + { + Y_ENSURE(RotatedFilesCount_ != 0); + } + inline void WriteData(const TLogRecord& rec) { if (static_cast<ui64>(AtomicGet(Size_)) > MaxSizeBytes_) { TWriteGuard guard(Lock_); if (static_cast<ui64>(AtomicGet(Size_)) > MaxSizeBytes_) { - TString newLogPath(TStringBuilder{} << Path_ << "." << RotatedFilesCount_); - for (size_t fileId = RotatedFilesCount_ - 1; fileId; --fileId) { - TString oldLogPath(TStringBuilder{} << Path_ << "." << fileId); - NFs::Rename(oldLogPath, newLogPath); - newLogPath = oldLogPath; - } - NFs::Rename(Path_, newLogPath); + TString newLogPath(TStringBuilder{} << Path_ << "." << RotatedFilesCount_); + for (size_t fileId = RotatedFilesCount_ - 1; fileId; --fileId) { + TString oldLogPath(TStringBuilder{} << Path_ << "." << fileId); + NFs::Rename(oldLogPath, newLogPath); + newLogPath = oldLogPath; + } + NFs::Rename(Path_, newLogPath); Log_.ReopenLog(); AtomicSet(Size_, 0); } @@ -54,23 +54,23 @@ public: TWriteGuard guard(Lock_); Log_.ReopenLog(); - AtomicSet(Size_, TFileStat(Path_).Size); + AtomicSet(Size_, TFileStat(Path_).Size); } private: TRWMutex Lock_; TFileLogBackend Log_; - const TString Path_; + const TString Path_; const ui64 MaxSizeBytes_; TAtomic Size_; - const ui32 RotatedFilesCount_; + const ui32 RotatedFilesCount_; }; -TRotatingFileLogBackend::TRotatingFileLogBackend(const TString& path, const ui64 maxSizeByte, const ui32 rotatedFilesCount) - : Impl_(new TImpl(path, maxSizeByte, rotatedFilesCount)) -{ -} - +TRotatingFileLogBackend::TRotatingFileLogBackend(const TString& path, const ui64 maxSizeByte, const ui32 rotatedFilesCount) + : Impl_(new TImpl(path, maxSizeByte, rotatedFilesCount)) +{ +} + TRotatingFileLogBackend::~TRotatingFileLogBackend() { } |