From b70a7c0dc25623640e43e382d0a6b394425e9ace Mon Sep 17 00:00:00 2001 From: Adam Grare Date: Tue, 12 Dec 2023 10:57:55 -0500 Subject: [PATCH] Extend wrapped_logger formatter if one is present If the logger_class has a Formatter we have to extend the wrapped_logger.formatter for it to take effect in both the broadcast and the wrapped loggers. --- lib/vmdb/loggers.rb | 3 +++ lib/vmdb/loggers/provider_sdk_logger.rb | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/vmdb/loggers.rb b/lib/vmdb/loggers.rb index 50b51806654..640a39b90d4 100644 --- a/lib/vmdb/loggers.rb +++ b/lib/vmdb/loggers.rb @@ -100,6 +100,9 @@ def logger.wrapped_logger end logger.extend(ActiveSupport::Logger.broadcast(wrapped_logger)) + if logger.class.const_defined?(:FormatterMixin) + wrapped_logger.formatter.extend(logger.class.const_get(:FormatterMixin)) + end wrapped_logger.progname = progname end diff --git a/lib/vmdb/loggers/provider_sdk_logger.rb b/lib/vmdb/loggers/provider_sdk_logger.rb index 325f9b691a9..43ea63a2ca4 100644 --- a/lib/vmdb/loggers/provider_sdk_logger.rb +++ b/lib/vmdb/loggers/provider_sdk_logger.rb @@ -14,7 +14,7 @@ def <<(msg) msg.size end - class Formatter < ManageIQ::Loggers::Base::Formatter + module FormatterMixin def call(severity, datetime, progname, msg) msg = msg.sub(/Bearer(.*?)\"/, 'Bearer [FILTERED] "') msg = msg.sub(/Basic(.*?)\"/, 'Basic [FILTERED] "') @@ -24,5 +24,9 @@ def call(severity, datetime, progname, msg) super(severity, datetime, progname, msg) end end + + class Formatter < ManageIQ::Loggers::Base::Formatter + include FormatterMixin + end end end