diff options
author | bixind <bixind@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 | f2f03a1ea0c5413acb624a532384109a1517130d (patch) | |
tree | 90b98b3eb5a62a4ee7109c2ab9bd99d5fdc836a6 /library/cpp | |
parent | 6ef3852e01d65430e2c0e50b3e646bd1ea019847 (diff) | |
download | ydb-f2f03a1ea0c5413acb624a532384109a1517130d.tar.gz |
Restoring authorship annotation for <bixind@yandex-team.ru>. Commit 1 of 2.
Diffstat (limited to 'library/cpp')
-rw-r--r-- | library/cpp/logger/rotating_file.cpp | 108 | ||||
-rw-r--r-- | library/cpp/logger/rotating_file.h | 36 | ||||
-rw-r--r-- | library/cpp/logger/rotating_file_ut.cpp | 16 | ||||
-rw-r--r-- | library/cpp/logger/ut/ya.make | 2 | ||||
-rw-r--r-- | library/cpp/logger/ya.make | 2 |
5 files changed, 82 insertions, 82 deletions
diff --git a/library/cpp/logger/rotating_file.cpp b/library/cpp/logger/rotating_file.cpp index a62f48f25d..86dc71e49c 100644 --- a/library/cpp/logger/rotating_file.cpp +++ b/library/cpp/logger/rotating_file.cpp @@ -1,25 +1,25 @@ -#include "rotating_file.h" -#include "file.h" -#include "record.h" - +#include "rotating_file.h" +#include "file.h" +#include "record.h" + #include <util/string/builder.h> -#include <util/system/fstat.h> -#include <util/system/rwlock.h> -#include <util/system/fs.h> -#include <util/system/atomic.h> -#include <util/generic/string.h> - -/* - * rotating file log +#include <util/system/fstat.h> +#include <util/system/rwlock.h> +#include <util/system/fs.h> +#include <util/system/atomic.h> +#include <util/generic/string.h> + +/* + * rotating file log * 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: + */ +class TRotatingFileLogBackend::TImpl { +public: inline TImpl(const TString& path, const ui64 maxSizeBytes, const ui32 rotatedFilesCount) : Log_(path) , Path_(path) @@ -30,10 +30,10 @@ public: 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_) { + 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); @@ -41,46 +41,46 @@ public: newLogPath = oldLogPath; } NFs::Rename(Path_, newLogPath); - Log_.ReopenLog(); - AtomicSet(Size_, 0); - } - } - TReadGuard guard(Lock_); - Log_.WriteData(rec); - AtomicAdd(Size_, rec.Len); - } - - inline void ReopenLog() { - TWriteGuard guard(Lock_); - - Log_.ReopenLog(); + Log_.ReopenLog(); + AtomicSet(Size_, 0); + } + } + TReadGuard guard(Lock_); + Log_.WriteData(rec); + AtomicAdd(Size_, rec.Len); + } + + inline void ReopenLog() { + TWriteGuard guard(Lock_); + + Log_.ReopenLog(); AtomicSet(Size_, TFileStat(Path_).Size); - } - -private: - TRWMutex Lock_; - TFileLogBackend Log_; + } + +private: + TRWMutex Lock_; + TFileLogBackend Log_; const TString Path_; - const ui64 MaxSizeBytes_; - TAtomic Size_; + const ui64 MaxSizeBytes_; + TAtomic Size_; const ui32 RotatedFilesCount_; -}; - +}; + TRotatingFileLogBackend::TRotatingFileLogBackend(const TString& path, const ui64 maxSizeByte, const ui32 rotatedFilesCount) : Impl_(new TImpl(path, maxSizeByte, rotatedFilesCount)) { } -TRotatingFileLogBackend::~TRotatingFileLogBackend() { -} - -void TRotatingFileLogBackend::WriteData(const TLogRecord& rec) { - Impl_->WriteData(rec); -} - -void TRotatingFileLogBackend::ReopenLog() { - TAtomicSharedPtr<TImpl> copy = Impl_; - if (copy) { - copy->ReopenLog(); - } -} +TRotatingFileLogBackend::~TRotatingFileLogBackend() { +} + +void TRotatingFileLogBackend::WriteData(const TLogRecord& rec) { + Impl_->WriteData(rec); +} + +void TRotatingFileLogBackend::ReopenLog() { + TAtomicSharedPtr<TImpl> copy = Impl_; + if (copy) { + copy->ReopenLog(); + } +} diff --git a/library/cpp/logger/rotating_file.h b/library/cpp/logger/rotating_file.h index cb047f25fb..dd585c4361 100644 --- a/library/cpp/logger/rotating_file.h +++ b/library/cpp/logger/rotating_file.h @@ -1,20 +1,20 @@ -#pragma once - -#include "backend.h" - +#pragma once + +#include "backend.h" + #include <util/generic/fwd.h> -#include <util/generic/ptr.h> - -class TRotatingFileLogBackend: public TLogBackend { -public: - TRotatingFileLogBackend(const TString& preRotatePath, const TString& postRotatePath, const ui64 maxSizeBytes); +#include <util/generic/ptr.h> + +class TRotatingFileLogBackend: public TLogBackend { +public: + TRotatingFileLogBackend(const TString& preRotatePath, const TString& postRotatePath, const ui64 maxSizeBytes); TRotatingFileLogBackend(const TString& path, const ui64 maxSizeBytes, const ui32 rotatedFilesCount); - ~TRotatingFileLogBackend() override; - - void WriteData(const TLogRecord& rec) override; - void ReopenLog() override; - -private: - class TImpl; - TAtomicSharedPtr<TImpl> Impl_; -}; + ~TRotatingFileLogBackend() override; + + void WriteData(const TLogRecord& rec) override; + void ReopenLog() override; + +private: + class TImpl; + TAtomicSharedPtr<TImpl> Impl_; +}; diff --git a/library/cpp/logger/rotating_file_ut.cpp b/library/cpp/logger/rotating_file_ut.cpp index 84966933d9..3ab590e664 100644 --- a/library/cpp/logger/rotating_file_ut.cpp +++ b/library/cpp/logger/rotating_file_ut.cpp @@ -1,13 +1,13 @@ -#include "rotating_file.h" -#include "record.h" - -#include <util/generic/string.h> -#include <util/system/fstat.h> -#include <util/system/fs.h> - +#include "rotating_file.h" +#include "record.h" + +#include <util/generic/string.h> +#include <util/system/fstat.h> +#include <util/system/fs.h> + #include <library/cpp/testing/unittest/registar.h> #include <library/cpp/testing/unittest/tests_data.h> - + Y_UNIT_TEST_SUITE(NewRotatingFileSuite) { const TString PATH = GetWorkPath() + "/my.log"; diff --git a/library/cpp/logger/ut/ya.make b/library/cpp/logger/ut/ya.make index 2a461c1353..e4f1a18c48 100644 --- a/library/cpp/logger/ut/ya.make +++ b/library/cpp/logger/ut/ya.make @@ -13,7 +13,7 @@ SRCDIR(library/cpp/logger) SRCS( log_ut.cpp element_ut.cpp - rotating_file_ut.cpp + rotating_file_ut.cpp composite_ut.cpp ) diff --git a/library/cpp/logger/ya.make b/library/cpp/logger/ya.make index 00a5263cba..7d54f565aa 100644 --- a/library/cpp/logger/ya.make +++ b/library/cpp/logger/ya.make @@ -29,7 +29,7 @@ SRCS( GLOBAL null_creator.cpp priority.h record.h - rotating_file.cpp + rotating_file.cpp GLOBAL rotating_file_creator.cpp stream.cpp GLOBAL stream_creator.cpp |