aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp
diff options
context:
space:
mode:
authorivanmorozov <ivanmorozov@yandex-team.com>2023-08-10 07:20:52 +0300
committerivanmorozov <ivanmorozov@yandex-team.com>2023-08-10 08:02:43 +0300
commit1d01d1e8552f3dbc090c0aa0d803a058073fed14 (patch)
treeae421a338e393a5833f2521cb36fac94d6f2cd6b /library/cpp
parent36bb339adf2db71a001899be4e136e0fd9e2099d (diff)
downloadydb-1d01d1e8552f3dbc090c0aa0d803a058073fed14.tar.gz
KIKIMR-18932:special verification for formatted stream writing
Diffstat (limited to 'library/cpp')
-rw-r--r--library/cpp/actors/core/log.cpp12
-rw-r--r--library/cpp/actors/core/log.h42
2 files changed, 51 insertions, 3 deletions
diff --git a/library/cpp/actors/core/log.cpp b/library/cpp/actors/core/log.cpp
index 1b6b0feba7..71b5d46c22 100644
--- a/library/cpp/actors/core/log.cpp
+++ b/library/cpp/actors/core/log.cpp
@@ -713,6 +713,10 @@ namespace NActors {
return TlsLogContext.Get().GetCurrentComponent().value_or(defComponent);
}
+ TLogRecordConstructor::TLogRecordConstructor() {
+ TBase::WriteDirectly(TlsLogContext.Get().GetCurrentHeader());
+ }
+
TFormattedRecordWriter::TFormattedRecordWriter(::NActors::NLog::EPriority priority, ::NActors::NLog::EComponent component)
: ActorContext(NActors::TlsActivationContext ? &NActors::TlsActivationContext->AsActorContext() : nullptr)
, Priority(priority)
@@ -720,4 +724,12 @@ namespace NActors {
TBase::WriteDirectly(TlsLogContext.Get().GetCurrentHeader());
}
+
+ TVerifyFormattedRecordWriter::TVerifyFormattedRecordWriter(const TString& conditionText)
+ : ConditionText(conditionText) {
+ TBase::WriteDirectly(TlsLogContext.Get().GetCurrentHeader());
+ TBase::Write("verification", ConditionText);
+
+ }
+
}
diff --git a/library/cpp/actors/core/log.h b/library/cpp/actors/core/log.h
index 6899fb9ca4..f9d3c54f97 100644
--- a/library/cpp/actors/core/log.h
+++ b/library/cpp/actors/core/log.h
@@ -15,6 +15,7 @@
#include <util/generic/vector.h>
#include <util/string/printf.h>
#include <util/string/builder.h>
+#include <util/system/yassert.h>
#include <library/cpp/logger/all.h>
#include <library/cpp/json/writer/json.h>
#include <library/cpp/svnversion/svnversion.h>
@@ -392,7 +393,7 @@ namespace NActors {
}
};
- class TFormatedStreamWriter {
+ class TFormatedStreamWriter: TNonCopyable {
private:
TStringBuilder Builder;
protected:
@@ -416,7 +417,7 @@ namespace NActors {
}
};
- class TLogContextBuilder: TNonCopyable, public TFormatedStreamWriter {
+ class TLogContextBuilder: public TFormatedStreamWriter {
private:
using TBase = TFormatedStreamWriter;
std::optional<::NActors::NLog::EComponent> Component;
@@ -440,7 +441,7 @@ namespace NActors {
}
};
- class TLogContextGuard: TNonCopyable, public TFormatedStreamWriter {
+ class TLogContextGuard: public TFormatedStreamWriter {
private:
using TBase = TFormatedStreamWriter;
std::optional<::NActors::NLog::EComponent> Component;
@@ -468,6 +469,20 @@ namespace NActors {
};
+ class TLogRecordConstructor: public TFormatedStreamWriter {
+ private:
+ using TBase = TFormatedStreamWriter;
+ public:
+
+ TLogRecordConstructor();
+
+ template <class TKey, class TValue>
+ TLogRecordConstructor& operator()(const TKey& pName, const TValue& pValue) {
+ TBase::Write(pName, pValue);
+ return *this;
+ }
+ };
+
class TFormattedRecordWriter: public TFormatedStreamWriter {
private:
using TBase = TFormatedStreamWriter;
@@ -493,8 +508,29 @@ namespace NActors {
}
};
+ class TVerifyFormattedRecordWriter: public TFormatedStreamWriter {
+ private:
+ using TBase = TFormatedStreamWriter;
+ const TString ConditionText;
+ public:
+
+ TVerifyFormattedRecordWriter(const TString& conditionText);
+
+ template <class TKey, class TValue>
+ TVerifyFormattedRecordWriter& operator()(const TKey& pName, const TValue& pValue) {
+ TBase::Write(pName, pValue);
+ return *this;
+ }
+
+ ~TVerifyFormattedRecordWriter() {
+ const TString data = TBase::GetResult();
+ Y_FAIL("%s", data.data());
+ }
+ };
}
+#define AFL_VERIFY(condition) if (condition); else TVerifyFormattedRecordWriter(#condition)("fline", TStringBuilder() << TStringBuf(__FILE__).RAfter(LOCSLASH_C) << ":" << __LINE__)
+
#define ACTORS_FORMATTED_LOG(mPriority, mComponent) \
if (NActors::TlsActivationContext && !IS_LOG_PRIORITY_ENABLED(mPriority, mComponent));\
else NActors::TFormattedRecordWriter(\