aboutsummaryrefslogtreecommitdiffstats
path: root/yt
diff options
context:
space:
mode:
authorignat <ignat@yandex-team.com>2023-10-13 04:27:05 +0300
committerignat <ignat@yandex-team.com>2023-10-13 04:47:13 +0300
commit51ca908b9821fc420b449a377f6df7d5902646b9 (patch)
tree63db41e48efb3905603ac4cde1057ce74cad8a6d /yt
parent17a004473eddb60b9e27d647b3c33fbc9dc514d3 (diff)
downloadydb-51ca908b9821fc420b449a377f6df7d5902646b9.tar.gz
YT-20201: add option to disable instant in structured log messages
Diffstat (limited to 'yt')
-rw-r--r--yt/yt/core/logging/config.cpp2
-rw-r--r--yt/yt/core/logging/config.h3
-rw-r--r--yt/yt/core/logging/formatter.cpp6
-rw-r--r--yt/yt/core/logging/formatter.h2
-rw-r--r--yt/yt/core/logging/log_manager.cpp1
-rw-r--r--yt/yt/core/logging/unittests/logging_ut.cpp1
6 files changed, 14 insertions, 1 deletions
diff --git a/yt/yt/core/logging/config.cpp b/yt/yt/core/logging/config.cpp
index de1721199f..81694f3d6f 100644
--- a/yt/yt/core/logging/config.cpp
+++ b/yt/yt/core/logging/config.cpp
@@ -92,6 +92,8 @@ void TLogWriterConfig::Register(TRegistrar registrar)
.Default();
registrar.Parameter("enable_source_location", &TThis::EnableSourceLocation)
.Default(false);
+ registrar.Parameter("enable_instant", &TThis::EnableInstant)
+ .Default(true);
registrar.Parameter("json_format", &TThis::JsonFormat)
.Default();
diff --git a/yt/yt/core/logging/config.h b/yt/yt/core/logging/config.h
index 112f086956..5dbebb21cc 100644
--- a/yt/yt/core/logging/config.h
+++ b/yt/yt/core/logging/config.h
@@ -89,6 +89,9 @@ public:
//! Plain text formatter options.
bool EnableSourceLocation;
+ //! Enable writing instant field.
+ bool EnableInstant;
+
//! Structured formatter options.
THashMap<TString, NYTree::INodePtr> CommonFields;
NJson::TJsonFormatConfigPtr JsonFormat;
diff --git a/yt/yt/core/logging/formatter.cpp b/yt/yt/core/logging/formatter.cpp
index fa982ad8f5..67e60bcd1c 100644
--- a/yt/yt/core/logging/formatter.cpp
+++ b/yt/yt/core/logging/formatter.cpp
@@ -137,11 +137,13 @@ TStructuredLogFormatter::TStructuredLogFormatter(
THashMap<TString, NYTree::INodePtr> commonFields,
bool enableSystemMessages,
bool enableSourceLocation,
+ bool enableInstant,
NJson::TJsonFormatConfigPtr jsonFormat)
: Format_(format)
, CommonFields_(std::move(commonFields))
, EnableSystemMessages_(enableSystemMessages)
, EnableSourceLocation_(enableSourceLocation)
+ , EnableInstant_(enableInstant)
, JsonFormat_(!jsonFormat && (Format_ == ELogFormat::Json)
? New<NJson::TJsonFormatConfig>()
: std::move(jsonFormat))
@@ -182,7 +184,9 @@ i64 TStructuredLogFormatter::WriteFormatted(IOutputStream* stream, const TLogEve
.DoIf(event.MessageKind == ELogMessageKind::Unstructured, [&] (auto fluent) {
fluent.Item("message").Value(event.MessageRef.ToStringBuf());
})
- .Item("instant").Value(dateTimeBuffer.GetBuffer())
+ .DoIf(EnableInstant_, [&] (auto fluent) {
+ fluent.Item("instant").Value(dateTimeBuffer.GetBuffer());
+ })
.Item("level").Value(FormatEnum(event.Level))
.Item("category").Value(event.Category->Name)
.DoIf(event.Family == ELogFamily::PlainText, [&] (auto fluent) {
diff --git a/yt/yt/core/logging/formatter.h b/yt/yt/core/logging/formatter.h
index 4d1086d51d..ebd034fa8f 100644
--- a/yt/yt/core/logging/formatter.h
+++ b/yt/yt/core/logging/formatter.h
@@ -53,6 +53,7 @@ public:
THashMap<TString, NYTree::INodePtr> commonFields,
bool enableControlMessages = true,
bool enableSourceLocation = false,
+ bool enableInstant = true,
NJson::TJsonFormatConfigPtr jsonFormat = nullptr);
i64 WriteFormatted(IOutputStream* outputStream, const TLogEvent& event) override;
@@ -65,6 +66,7 @@ private:
const THashMap<TString, NYTree::INodePtr> CommonFields_;
const bool EnableSystemMessages_;
const bool EnableSourceLocation_;
+ const bool EnableInstant_;
const NJson::TJsonFormatConfigPtr JsonFormat_;
TCachingDateFormatter CachingDateFormatter_;
diff --git a/yt/yt/core/logging/log_manager.cpp b/yt/yt/core/logging/log_manager.cpp
index 5b509b9470..e254032e20 100644
--- a/yt/yt/core/logging/log_manager.cpp
+++ b/yt/yt/core/logging/log_manager.cpp
@@ -845,6 +845,7 @@ private:
writerConfig->CommonFields,
writerConfig->AreSystemMessagesEnabled(),
writerConfig->EnableSourceLocation,
+ writerConfig->EnableInstant,
writerConfig->JsonFormat);
default:
diff --git a/yt/yt/core/logging/unittests/logging_ut.cpp b/yt/yt/core/logging/unittests/logging_ut.cpp
index 2337d0d7a8..68472ab0f7 100644
--- a/yt/yt/core/logging/unittests/logging_ut.cpp
+++ b/yt/yt/core/logging/unittests/logging_ut.cpp
@@ -659,6 +659,7 @@ TEST_F(TLoggingTest, StructuredLoggingJsonFormat)
/*commonFields*/ THashMap<TString, INodePtr>{},
/*enableControlMessages*/ true,
/*enableSourceLocation*/ false,
+ /*enableInstant*/ true,
jsonFormat);
auto writer = CreateFileLogWriter(