aboutsummaryrefslogtreecommitdiffstats
path: root/yt
diff options
context:
space:
mode:
authorrobot-ydb-importer <robot-ydb-importer@yandex-team.com>2024-01-19 19:09:00 +0300
committerrobot-ydb-importer <robot-ydb-importer@yandex-team.com>2024-01-19 19:28:11 +0300
commit8b8a5397387a4257ef3311d0a02541fbcb13d5f8 (patch)
treed6443537aa57c4ef7bc18e823c0a4c775ab61715 /yt
parent2e2b97c2fa1d8cce987480a460d6c32493b6b4f3 (diff)
downloadydb-8b8a5397387a4257ef3311d0a02541fbcb13d5f8.tar.gz
YDB Import 546
Diffstat (limited to 'yt')
-rw-r--r--yt/yt/core/logging/formatter.cpp39
-rw-r--r--yt/yt/core/logging/formatter.h28
2 files changed, 48 insertions, 19 deletions
diff --git a/yt/yt/core/logging/formatter.cpp b/yt/yt/core/logging/formatter.cpp
index 67e60bcd1c..75a3c4f5be 100644
--- a/yt/yt/core/logging/formatter.cpp
+++ b/yt/yt/core/logging/formatter.cpp
@@ -1,7 +1,6 @@
#include "formatter.h"
#include "private.h"
-// #include "log.h"
#include <yt/yt/build/build.h>
@@ -9,8 +8,6 @@
#include <yt/yt/core/ytree/fluent.h>
-// #include <yt/yt/core/yson/writer.h>
-
#include <util/stream/length.h>
namespace NYT::NLogging {
@@ -92,7 +89,7 @@ TLogEvent GetSkippedLogStructuredEvent(i64 count, TStringBuf skippedBy)
TPlainTextLogFormatter::TPlainTextLogFormatter(
bool enableSystemMessages,
bool enableSourceLocation)
- : EnableSystemMessages_(enableSystemMessages && Logger)
+ : TLogFormatterBase(enableSystemMessages, enableSourceLocation)
, EventFormatter_(enableSourceLocation)
{ }
@@ -118,20 +115,39 @@ void TPlainTextLogFormatter::WriteLogReopenSeparator(IOutputStream* outputStream
void TPlainTextLogFormatter::WriteLogStartEvent(IOutputStream* outputStream)
{
- if (EnableSystemMessages_) {
+ if (AreSystemMessagesEnabled()) {
WriteFormatted(outputStream, GetStartLogEvent());
}
}
void TPlainTextLogFormatter::WriteLogSkippedEvent(IOutputStream* outputStream, i64 count, TStringBuf skippedBy)
{
- if (EnableSystemMessages_) {
+ if (AreSystemMessagesEnabled()) {
WriteFormatted(outputStream, GetSkippedLogEvent(count, skippedBy));
}
}
////////////////////////////////////////////////////////////////////////////////
+TLogFormatterBase::TLogFormatterBase(
+ bool enableSystemMessages,
+ bool enableSourceLocation)
+ : EnableSystemMessages_(enableSystemMessages)
+ , EnableSourceLocation_(enableSourceLocation)
+{ }
+
+bool TLogFormatterBase::AreSystemMessagesEnabled() const
+{
+ return EnableSystemMessages_ && GetDefaultLogManager();
+}
+
+bool TLogFormatterBase::IsSourceLocationEnabled() const
+{
+ return EnableSourceLocation_;
+}
+
+////////////////////////////////////////////////////////////////////////////////
+
TStructuredLogFormatter::TStructuredLogFormatter(
ELogFormat format,
THashMap<TString, NYTree::INodePtr> commonFields,
@@ -139,10 +155,9 @@ TStructuredLogFormatter::TStructuredLogFormatter(
bool enableSourceLocation,
bool enableInstant,
NJson::TJsonFormatConfigPtr jsonFormat)
- : Format_(format)
+ : TLogFormatterBase(enableSystemMessages, enableSourceLocation)
+ , Format_(format)
, CommonFields_(std::move(commonFields))
- , EnableSystemMessages_(enableSystemMessages)
- , EnableSourceLocation_(enableSourceLocation)
, EnableInstant_(enableInstant)
, JsonFormat_(!jsonFormat && (Format_ == ELogFormat::Json)
? New<NJson::TJsonFormatConfig>()
@@ -196,7 +211,7 @@ i64 TStructuredLogFormatter::WriteFormatted(IOutputStream* stream, const TLogEve
if (event.TraceId != TTraceId()) {
fluent.Item("trace_id").Value(event.TraceId);
}
- if (EnableSourceLocation_ && event.SourceFile) {
+ if (IsSourceLocationEnabled() && event.SourceFile) {
auto sourceFile = event.SourceFile;
fluent.Item("source_file").Value(Format("%v:%v", sourceFile.RNextTok(LOCSLASH_C), event.SourceLine));
}
@@ -219,14 +234,14 @@ void TStructuredLogFormatter::WriteLogReopenSeparator(IOutputStream* /*outputStr
void TStructuredLogFormatter::WriteLogStartEvent(IOutputStream* outputStream)
{
- if (EnableSystemMessages_) {
+ if (AreSystemMessagesEnabled()) {
WriteFormatted(outputStream, GetStartLogStructuredEvent());
}
}
void TStructuredLogFormatter::WriteLogSkippedEvent(IOutputStream* outputStream, i64 count, TStringBuf skippedBy)
{
- if (EnableSystemMessages_) {
+ if (AreSystemMessagesEnabled()) {
WriteFormatted(outputStream, GetSkippedLogStructuredEvent(count, skippedBy));
}
}
diff --git a/yt/yt/core/logging/formatter.h b/yt/yt/core/logging/formatter.h
index ebd034fa8f..2c92fc0d5c 100644
--- a/yt/yt/core/logging/formatter.h
+++ b/yt/yt/core/logging/formatter.h
@@ -22,9 +22,27 @@ struct ILogFormatter
////////////////////////////////////////////////////////////////////////////////
-class TPlainTextLogFormatter
+class TLogFormatterBase
: public ILogFormatter
{
+protected:
+ TLogFormatterBase(
+ bool enableSystemMessages,
+ bool enableSourceLocation);
+
+ bool AreSystemMessagesEnabled() const;
+ bool IsSourceLocationEnabled() const;
+
+private:
+ const bool EnableSystemMessages_;
+ const bool EnableSourceLocation_;
+};
+
+////////////////////////////////////////////////////////////////////////////////
+
+class TPlainTextLogFormatter
+ : public TLogFormatterBase
+{
public:
explicit TPlainTextLogFormatter(
bool enableControlMessages = true,
@@ -36,8 +54,6 @@ public:
void WriteLogSkippedEvent(IOutputStream* outputStream, i64 count, TStringBuf skippedBy) override;
private:
- const bool EnableSystemMessages_;
-
TRawFormatter<MessageBufferSize> Buffer_;
TPlainTextEventFormatter EventFormatter_;
};
@@ -45,13 +61,13 @@ private:
////////////////////////////////////////////////////////////////////////////////
class TStructuredLogFormatter
- : public ILogFormatter
+ : public TLogFormatterBase
{
public:
TStructuredLogFormatter(
ELogFormat format,
THashMap<TString, NYTree::INodePtr> commonFields,
- bool enableControlMessages = true,
+ bool enablSystemlMessages = true,
bool enableSourceLocation = false,
bool enableInstant = true,
NJson::TJsonFormatConfigPtr jsonFormat = nullptr);
@@ -64,8 +80,6 @@ public:
private:
const ELogFormat Format_;
const THashMap<TString, NYTree::INodePtr> CommonFields_;
- const bool EnableSystemMessages_;
- const bool EnableSourceLocation_;
const bool EnableInstant_;
const NJson::TJsonFormatConfigPtr JsonFormat_;