aboutsummaryrefslogtreecommitdiffstats
path: root/library/cpp/actors/core
diff options
context:
space:
mode:
authorivanmorozov <ivanmorozov@yandex-team.com>2023-04-17 11:15:04 +0300
committerivanmorozov <ivanmorozov@yandex-team.com>2023-04-17 11:15:04 +0300
commit8ebea9ad43c451efd60d88399828c90a28599b10 (patch)
tree5f11b950e6b446511e56afd8deb80896e402b7e7 /library/cpp/actors/core
parent8454af646f2165b93c5d7e2e6e48e0ffcd135c5b (diff)
downloadydb-8ebea9ad43c451efd60d88399828c90a28599b10.tar.gz
log formatting
Diffstat (limited to 'library/cpp/actors/core')
-rw-r--r--library/cpp/actors/core/log.h52
1 files changed, 52 insertions, 0 deletions
diff --git a/library/cpp/actors/core/log.h b/library/cpp/actors/core/log.h
index a57d7be1da..f9bbdbe914 100644
--- a/library/cpp/actors/core/log.h
+++ b/library/cpp/actors/core/log.h
@@ -388,8 +388,40 @@ namespace NActors {
}
};
+ class TFormattedRecordWriter {
+ private:
+ const TActorContext& ActorContext;
+ ::NActors::NLog::EPriority Priority = ::NActors::NLog::EPriority::PRI_INFO;
+ ::NActors::NLog::EComponent Component = 0;
+ TStringBuilder Builder;
+ public:
+
+ TFormattedRecordWriter(const TActorContext& actorContext, ::NActors::NLog::EPriority priority, ::NActors::NLog::EComponent component)
+ : ActorContext(actorContext)
+ , Priority(priority)
+ , Component(component) {
+
+ }
+
+ template <class TKey, class TValue>
+ TFormattedRecordWriter& operator()(const TKey& pName, const TValue& pValue) {
+ Builder << pName << "=" << pValue << ";";
+ return *this;
+ }
+
+ ~TFormattedRecordWriter() {
+ ::NActors::MemLogAdapter(ActorContext, Priority, Component, Builder);
+ }
+ };
+
}
+#define ACTORS_FORMATTED_LOG(actorCtxOrSystem, mPriority, mComponent) \
+ if (!IS_LOG_PRIORITY_ENABLED(actorCtxOrSystem, mPriority, mComponent));\
+ else NActors::TFormattedRecordWriter(\
+ actorCtxOrSystem, static_cast<::NActors::NLog::EPriority>(mPriority), static_cast<::NActors::NLog::EComponent>(mComponent)\
+ )("fline", TStringBuilder() << TStringBuf(__FILE__).RAfter(LOCSLASH_C) << ":" << __LINE__)
+
#define ACTORS_LOG_STREAM(actorCtxOrSystem, mPriority, mComponent) \
if (!IS_LOG_PRIORITY_ENABLED(actorCtxOrSystem, mPriority, mComponent));\
else NActors::TRecordWriter(\
@@ -416,3 +448,23 @@ namespace NActors {
#define ALS_ALERT(component) ACTORS_LOG_STREAM_ALERT(NActors::TActivationContext::AsActorContext(), component)
#define ALS_EMERG(component) ACTORS_LOG_STREAM_EMERG(NActors::TActivationContext::AsActorContext(), component)
+#define ACTORS_FORMATTED_LOG_TRACE(actorCtxOrSystem, component) ACTORS_FORMATTED_LOG(actorCtxOrSystem, NActors::NLog::PRI_TRACE, component)
+#define ACTORS_FORMATTED_LOG_DEBUG(actorCtxOrSystem, component) ACTORS_FORMATTED_LOG(actorCtxOrSystem, NActors::NLog::PRI_DEBUG, component)
+#define ACTORS_FORMATTED_LOG_INFO(actorCtxOrSystem, component) ACTORS_FORMATTED_LOG(actorCtxOrSystem, NActors::NLog::PRI_INFO, component)
+#define ACTORS_FORMATTED_LOG_NOTICE(actorCtxOrSystem, component) ACTORS_FORMATTED_LOG(actorCtxOrSystem, NActors::NLog::PRI_NOTICE, component)
+#define ACTORS_FORMATTED_LOG_WARN(actorCtxOrSystem, component) ACTORS_FORMATTED_LOG(actorCtxOrSystem, NActors::NLog::PRI_WARN, component)
+#define ACTORS_FORMATTED_LOG_ERROR(actorCtxOrSystem, component) ACTORS_FORMATTED_LOG(actorCtxOrSystem, NActors::NLog::PRI_ERROR, component)
+#define ACTORS_FORMATTED_LOG_CRIT(actorCtxOrSystem, component) ACTORS_FORMATTED_LOG(actorCtxOrSystem, NActors::NLog::PRI_CRIT, component)
+#define ACTORS_FORMATTED_LOG_ALERT(actorCtxOrSystem, component) ACTORS_FORMATTED_LOG(actorCtxOrSystem, NActors::NLog::PRI_ALERT, component)
+#define ACTORS_FORMATTED_LOG_EMERG(actorCtxOrSystem, component) ACTORS_FORMATTED_LOG(actorCtxOrSystem, NActors::NLog::PRI_EMERG, component)
+
+#define AFL_TRACE(component) ACTORS_FORMATTED_LOG_TRACE(NActors::TActivationContext::AsActorContext(), component)
+#define AFL_DEBUG(component) ACTORS_FORMATTED_LOG_DEBUG(NActors::TActivationContext::AsActorContext(), component)
+#define AFL_INFO(component) ACTORS_FORMATTED_LOG_INFO(NActors::TActivationContext::AsActorContext(), component)
+#define AFL_NOTICE(component) ACTORS_FORMATTED_LOG_NOTICE(NActors::TActivationContext::AsActorContext(), component)
+#define AFL_WARN(component) ACTORS_FORMATTED_LOG_WARN(NActors::TActivationContext::AsActorContext(), component)
+#define AFL_ERROR(component) ACTORS_FORMATTED_LOG_ERROR(NActors::TActivationContext::AsActorContext(), component)
+#define AFL_CRIT(component) ACTORS_FORMATTED_LOG_CRIT(NActors::TActivationContext::AsActorContext(), component)
+#define AFL_ALERT(component) ACTORS_FORMATTED_LOG_ALERT(NActors::TActivationContext::AsActorContext(), component)
+#define AFL_EMERG(component) ACTORS_FORMATTED_LOG_EMERG(NActors::TActivationContext::AsActorContext(), component)
+