Skip to content

Commit

Permalink
Enable static validation of the EVENT log macros
Browse files Browse the repository at this point in the history
Signed-off-by: Yan Avlasov <[email protected]>
  • Loading branch information
yanavlasov committed Mar 22, 2024
1 parent 79c64c5 commit 0a318be
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
11 changes: 11 additions & 0 deletions source/common/common/logger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,17 @@ void DelegatingLogSink::setTlsDelegate(SinkDelegate* sink) { *tlsSink() = sink;

SinkDelegate* DelegatingLogSink::tlsDelegate() { return *tlsSink(); }

void DelegatingLogSink::logWithStableName(absl::string_view stable_name, absl::string_view level,
absl::string_view component, absl::string_view message) {
auto tls_sink = tlsDelegate();
if (tls_sink != nullptr) {
tls_sink->logWithStableName(stable_name, level, component, message);
return;
}
absl::ReaderMutexLock sink_lock(&sink_mutex_);
sink_->logWithStableName(stable_name, level, component, message);
}

static std::atomic<Context*> current_context = nullptr;
static_assert(std::atomic<Context*>::is_always_lock_free);

Expand Down
20 changes: 5 additions & 15 deletions source/common/common/logger.h
Original file line number Diff line number Diff line change
Expand Up @@ -205,19 +205,8 @@ class DelegatingLogSink : public spdlog::sinks::sink {
void setLock(Thread::BasicLockable& lock) { stderr_sink_->setLock(lock); }
void clearLock() { stderr_sink_->clearLock(); }

template <class FmtStr, class... Args>
void logWithStableName(absl::string_view stable_name, absl::string_view level,
absl::string_view component, FmtStr fmt_str, Args... msg) {
auto tls_sink = tlsDelegate();
if (tls_sink != nullptr) {
tls_sink->logWithStableName(stable_name, level, component,
fmt::format(fmt::runtime(fmt_str), msg...));
return;
}
absl::ReaderMutexLock sink_lock(&sink_mutex_);
sink_->logWithStableName(stable_name, level, component,
fmt::format(fmt::runtime(fmt_str), msg...));
}
absl::string_view component, absl::string_view message);
// spdlog::sinks::sink
void log(const spdlog::details::log_msg& msg) override;
void flush() override;
Expand Down Expand Up @@ -657,7 +646,7 @@ class ExtractedMessage : public spdlog::custom_flag_formatter {
ENVOY_LOG_TO_LOGGER(LOGGER, LEVEL, ##__VA_ARGS__); \
if (ENVOY_LOG_COMP_LEVEL(LOGGER, LEVEL)) { \
::Envoy::Logger::Registry::getSink()->logWithStableName(EVENT_NAME, #LEVEL, (LOGGER).name(), \
##__VA_ARGS__); \
fmt::format(__VA_ARGS__)); \
} \
} while (0)

Expand All @@ -669,8 +658,9 @@ class ExtractedMessage : public spdlog::custom_flag_formatter {
ENVOY_LOG_TO_LOGGER(ENVOY_LOGGER(), LEVEL, "{}" FORMAT, \
::Envoy::Logger::Utility::serializeLogTags(log_tags), ##__VA_ARGS__); \
::Envoy::Logger::Registry::getSink()->logWithStableName( \
EVENT_NAME, #LEVEL, (ENVOY_LOGGER()).name(), "{}" FORMAT, \
::Envoy::Logger::Utility::serializeLogTags(log_tags), ##__VA_ARGS__); \
EVENT_NAME, #LEVEL, (ENVOY_LOGGER()).name(), \
fmt::format("{}" FORMAT, ::Envoy::Logger::Utility::serializeLogTags(log_tags), \
##__VA_ARGS__)); \
} \
} while (0)

Expand Down

0 comments on commit 0a318be

Please sign in to comment.