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 | 4b28e15652a7672062edb6804bc985eedc333257 (patch) | |
tree | 5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/logger/rotating_file.cpp | |
parent | e8fdd1e6c0645bf1702aaf85cc7460dbd09977cb (diff) | |
download | ydb-4b28e15652a7672062edb6804bc985eedc333257.tar.gz |
Restoring authorship annotation for <danibw@yandex-team.ru>. Commit 2 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 3391d26002..a62f48f25d 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() { } |