summaryrefslogtreecommitdiffstats
path: root/library/cpp/logger
diff options
context:
space:
mode:
authordanibw <[email protected]>2022-02-10 16:50:12 +0300
committerDaniil Cherednik <[email protected]>2022-02-10 16:50:12 +0300
commite8fdd1e6c0645bf1702aaf85cc7460dbd09977cb (patch)
treed96a47e62e16b199f4ffbf41f6848e9fad7dfa21 /library/cpp/logger
parentdf6eb5b163c763cd9633a4850cfae72f8d742996 (diff)
Restoring authorship annotation for <[email protected]>. Commit 1 of 2.
Diffstat (limited to 'library/cpp/logger')
-rw-r--r--library/cpp/logger/rotating_file.cpp64
-rw-r--r--library/cpp/logger/rotating_file.h2
-rw-r--r--library/cpp/logger/rotating_file_ut.cpp68
3 files changed, 67 insertions, 67 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() {
}
diff --git a/library/cpp/logger/rotating_file.h b/library/cpp/logger/rotating_file.h
index cb047f25fbd..8f5f834fbbc 100644
--- a/library/cpp/logger/rotating_file.h
+++ b/library/cpp/logger/rotating_file.h
@@ -8,7 +8,7 @@
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(const TString& path, const ui64 maxSizeBytes, const ui32 rotatedFilesCount);
~TRotatingFileLogBackend() override;
void WriteData(const TLogRecord& rec) override;
diff --git a/library/cpp/logger/rotating_file_ut.cpp b/library/cpp/logger/rotating_file_ut.cpp
index 84966933d96..6cfa41da803 100644
--- a/library/cpp/logger/rotating_file_ut.cpp
+++ b/library/cpp/logger/rotating_file_ut.cpp
@@ -8,38 +8,38 @@
#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";
-
- Y_UNIT_TEST(TestFileWrite) {
- TRotatingFileLogBackend log(PATH, 4000, 2);
- TString data = "my data";
- log.WriteData(TLogRecord(ELogPriority::TLOG_INFO, data.data(), data.size()));
- UNIT_ASSERT_C(TFileStat(PATH).Size > 0, "file " << PATH << " has zero size");
- }
-
- Y_UNIT_TEST(TestFileRotate) {
- const ui64 maxSize = 40;
- TRotatingFileLogBackend log(PATH, maxSize, 2);
- TStringBuilder data;
- for (size_t i = 0; i < 10; ++i)
- data << "data\n";
- log.WriteData(TLogRecord(ELogPriority::TLOG_INFO, data.data(), data.size()));
- UNIT_ASSERT_C(TFileStat(PATH).Size > 0, "file " << PATH << " has zero size");
- data.clear();
- data << "more data";
- log.WriteData(TLogRecord(ELogPriority::TLOG_INFO, data.data(), data.size()));
- UNIT_ASSERT_C(TFileStat(PATH).Size > 0, "file " << PATH << " has zero size");
- UNIT_ASSERT_C(TFileStat(TStringBuilder{} << PATH << ".1").Size > 0, "file " << PATH << ".1 has zero size");
- UNIT_ASSERT_C(TFileStat(PATH).Size < maxSize, "size of file " << PATH << " is greater than the size limit of " << maxSize << " bytes");
- }
-
- Y_UNIT_TEST(TestDoubleFileRotate) {
- const ui64 maxSize = 40;
- TRotatingFileLogBackend log(PATH, maxSize, 2);
- TStringBuilder data;
- for (size_t i = 0; i < 10; ++i)
- data << "data\n";
+Y_UNIT_TEST_SUITE(NewRotatingFileSuite) {
+ const TString PATH = GetWorkPath() + "/my.log";
+
+ Y_UNIT_TEST(TestFileWrite) {
+ TRotatingFileLogBackend log(PATH, 4000, 2);
+ TString data = "my data";
+ log.WriteData(TLogRecord(ELogPriority::TLOG_INFO, data.data(), data.size()));
+ UNIT_ASSERT_C(TFileStat(PATH).Size > 0, "file " << PATH << " has zero size");
+ }
+
+ Y_UNIT_TEST(TestFileRotate) {
+ const ui64 maxSize = 40;
+ TRotatingFileLogBackend log(PATH, maxSize, 2);
+ TStringBuilder data;
+ for (size_t i = 0; i < 10; ++i)
+ data << "data\n";
+ log.WriteData(TLogRecord(ELogPriority::TLOG_INFO, data.data(), data.size()));
+ UNIT_ASSERT_C(TFileStat(PATH).Size > 0, "file " << PATH << " has zero size");
+ data.clear();
+ data << "more data";
+ log.WriteData(TLogRecord(ELogPriority::TLOG_INFO, data.data(), data.size()));
+ UNIT_ASSERT_C(TFileStat(PATH).Size > 0, "file " << PATH << " has zero size");
+ UNIT_ASSERT_C(TFileStat(TStringBuilder{} << PATH << ".1").Size > 0, "file " << PATH << ".1 has zero size");
+ UNIT_ASSERT_C(TFileStat(PATH).Size < maxSize, "size of file " << PATH << " is greater than the size limit of " << maxSize << " bytes");
+ }
+
+ Y_UNIT_TEST(TestDoubleFileRotate) {
+ const ui64 maxSize = 40;
+ TRotatingFileLogBackend log(PATH, maxSize, 2);
+ TStringBuilder data;
+ for (size_t i = 0; i < 10; ++i)
+ data << "data\n";
log.WriteData(TLogRecord(ELogPriority::TLOG_INFO, data.data(), data.size()));
UNIT_ASSERT_C(TFileStat(PATH).Size > 0, "file " << PATH << " has zero size");
log.WriteData(TLogRecord(ELogPriority::TLOG_INFO, data.data(), data.size()));
@@ -53,5 +53,5 @@ Y_UNIT_TEST_SUITE(NewRotatingFileSuite) {
UNIT_ASSERT_C(TFileStat(TStringBuilder{} << PATH << ".1").Size > 0, "file " << PATH << ".1 has zero size");
UNIT_ASSERT_C(TFileStat(TStringBuilder{} << PATH << ".2").Size > 0, "file " << PATH << ".2 has zero size");
UNIT_ASSERT_C(TFileStat(PATH).Size < maxSize, "size of file " << PATH << " is greater than the size limit of " << maxSize << " bytes");
- }
-}
+ }
+}