diff options
author | Alexander Smirnov <alex@ydb.tech> | 2024-10-21 10:21:33 +0000 |
---|---|---|
committer | Alexander Smirnov <alex@ydb.tech> | 2024-10-21 10:21:33 +0000 |
commit | 4eca37ecd81a80606e9c2afed5401f15d15e3671 (patch) | |
tree | edb21b983f86981f8ed77704231cbe589bc19bdd /library/cpp | |
parent | 7f4d37b99e25e931918580a353dba7eed11407ee (diff) | |
parent | d3ed30f2deefe6a5ed0d07a3018c723749ca5d7b (diff) | |
download | ydb-4eca37ecd81a80606e9c2afed5401f15d15e3671.tar.gz |
Merge branch 'rightlib' into mergelibs-241021-1020
Diffstat (limited to 'library/cpp')
-rw-r--r-- | library/cpp/tld/tlds-alpha-by-domain.txt | 2 | ||||
-rw-r--r-- | library/cpp/yt/logging/backends/stream/stream_log_manager.cpp | 6 | ||||
-rw-r--r-- | library/cpp/yt/logging/logger-inl.h | 15 | ||||
-rw-r--r-- | library/cpp/yt/logging/logger.h | 34 |
4 files changed, 36 insertions, 21 deletions
diff --git a/library/cpp/tld/tlds-alpha-by-domain.txt b/library/cpp/tld/tlds-alpha-by-domain.txt index 055d440b6ec..0e38681a50e 100644 --- a/library/cpp/tld/tlds-alpha-by-domain.txt +++ b/library/cpp/tld/tlds-alpha-by-domain.txt @@ -1,4 +1,4 @@ -# Version 2024101600, Last Updated Wed Oct 16 07:07:02 2024 UTC +# Version 2024101900, Last Updated Sat Oct 19 07:07:02 2024 UTC AAA AARP ABB diff --git a/library/cpp/yt/logging/backends/stream/stream_log_manager.cpp b/library/cpp/yt/logging/backends/stream/stream_log_manager.cpp index 62269dc0c0d..62fa3e91d05 100644 --- a/library/cpp/yt/logging/backends/stream/stream_log_manager.cpp +++ b/library/cpp/yt/logging/backends/stream/stream_log_manager.cpp @@ -28,10 +28,8 @@ public: anchor->Registered = true; } - virtual void UpdateAnchor(TLoggingAnchor* anchor) override - { - anchor->Enabled = true; - } + virtual void UpdateAnchor(TLoggingAnchor* /*anchor*/) override + { } virtual void Enqueue(TLogEvent&& event) override { diff --git a/library/cpp/yt/logging/logger-inl.h b/library/cpp/yt/logging/logger-inl.h index f3993a4c48a..f1be10827f9 100644 --- a/library/cpp/yt/logging/logger-inl.h +++ b/library/cpp/yt/logging/logger-inl.h @@ -14,11 +14,11 @@ namespace NYT::NLogging { //////////////////////////////////////////////////////////////////////////////// -inline bool TLogger::IsAnchorUpToDate(const TLoggingAnchor& position) const +inline bool TLogger::IsAnchorUpToDate(const TLoggingAnchor& anchor) const { return !Category_ || - position.CurrentVersion == Category_->ActualVersion->load(std::memory_order::relaxed); + anchor.CurrentVersion == Category_->ActualVersion->load(std::memory_order::relaxed); } template <class... TArgs> @@ -49,6 +49,17 @@ TLogger TLogger::WithStructuredTag(TStringBuf key, TType value) const return result; } +Y_FORCE_INLINE ELogLevel TLogger::GetEffectiveLoggingLevel(ELogLevel level, const TLoggingAnchor& anchor) +{ + // Check if anchor is suppressed. + if (anchor.Suppressed.load(std::memory_order::relaxed)) { + return ELogLevel::Minimum; + } + + // Compute the actual level taking anchor override into account. + return anchor.LevelOverride.load(std::memory_order::relaxed).value_or(level); +} + Y_FORCE_INLINE bool TLogger::IsLevelEnabled(ELogLevel level) const { // This is the first check which is intended to be inlined next to diff --git a/library/cpp/yt/logging/logger.h b/library/cpp/yt/logging/logger.h index 4f0ed44ab7e..35aba4eb4c4 100644 --- a/library/cpp/yt/logging/logger.h +++ b/library/cpp/yt/logging/logger.h @@ -47,12 +47,17 @@ struct TLoggingCategory struct TLoggingAnchor { std::atomic<bool> Registered = false; + TLoggingAnchor* NextAnchor = nullptr; + ::TSourceLocation SourceLocation = {TStringBuf{}, 0}; TString AnchorMessage; - TLoggingAnchor* NextAnchor = nullptr; std::atomic<int> CurrentVersion = 0; - std::atomic<bool> Enabled = false; + + std::atomic<bool> Suppressed = false; + + std::atomic<std::optional<ELogLevel>> LevelOverride; + static_assert(decltype(LevelOverride)::is_always_lock_free); struct TCounter { @@ -189,6 +194,9 @@ public: const TLoggingCategory* GetCategory() const; + //! Combines given #level and the override from #anchor. + static ELogLevel GetEffectiveLoggingLevel(ELogLevel level, const TLoggingAnchor& anchor); + //! Validate that level is admitted by logger's own min level //! and by category's min level. bool IsLevelEnabled(ELogLevel level) const; @@ -300,40 +308,38 @@ void LogStructuredEvent( do { \ const auto& logger__ = (logger)(); \ auto level__ = (level); \ - \ - if (!logger__.IsLevelEnabled(level__)) { \ - break; \ - } \ - \ auto location__ = __LOCATION__; \ \ ::NYT::NLogging::TLoggingAnchor* anchor__ = (anchor); \ - if (!anchor__) { \ + [[unlikely]] if (!anchor__) { \ static ::NYT::TLeakyStorage<::NYT::NLogging::TLoggingAnchor> staticAnchor__; \ anchor__ = staticAnchor__.Get(); \ } \ \ bool anchorUpToDate__ = logger__.IsAnchorUpToDate(*anchor__); \ - if (anchorUpToDate__ && !anchor__->Enabled.load(std::memory_order::relaxed)) { \ - break; \ + [[likely]] if (anchorUpToDate__) { \ + auto effectiveLevel__ = ::NYT::NLogging::TLogger::GetEffectiveLoggingLevel(level__, *anchor__); \ + if (!logger__.IsLevelEnabled(effectiveLevel__)) { \ + break; \ + } \ } \ \ auto loggingContext__ = ::NYT::NLogging::GetLoggingContext(); \ auto message__ = ::NYT::NLogging::NDetail::BuildLogMessage(loggingContext__, logger__, __VA_ARGS__); \ \ - if (!anchorUpToDate__) { \ + [[unlikely]] if (!anchorUpToDate__) { \ logger__.RegisterStaticAnchor(anchor__, location__, message__.Anchor); \ - logger__.UpdateAnchor(anchor__); \ } \ \ - if (!anchor__->Enabled.load(std::memory_order::relaxed)) { \ + auto effectiveLevel__ = ::NYT::NLogging::TLogger::GetEffectiveLoggingLevel(level__, *anchor__); \ + if (!logger__.IsLevelEnabled(effectiveLevel__)) { \ break; \ } \ \ ::NYT::NLogging::NDetail::LogEventImpl( \ loggingContext__, \ logger__, \ - level__, \ + effectiveLevel__, \ location__, \ anchor__, \ std::move(message__.MessageRef)); \ |