aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/logger/rotating_file.cpp
diff options
context:
space:
mode:
authorbixind <bixind@yandex-team.ru>2022-02-10 16:50:12 +0300
committerDaniil Cherednik <dcherednik@yandex-team.ru>2022-02-10 16:50:12 +0300
commitdf6eb5b163c763cd9633a4850cfae72f8d742996 (patch)
tree5d5cb817648f650d76cf1076100726fd9b8448e8 /library/cpp/logger/rotating_file.cpp
parentf2f03a1ea0c5413acb624a532384109a1517130d (diff)
downloadydb-df6eb5b163c763cd9633a4850cfae72f8d742996.tar.gz
Restoring authorship annotation for <bixind@yandex-team.ru>. Commit 2 of 2.
Diffstat (limited to 'library/cpp/logger/rotating_file.cpp')
-rw-r--r--library/cpp/logger/rotating_file.cpp108
1 files changed, 54 insertions, 54 deletions
diff --git a/library/cpp/logger/rotating_file.cpp b/library/cpp/logger/rotating_file.cpp
index 86dc71e49c..a62f48f25d 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();
+ }
+}