Skip to content

Commit

Permalink
Extend wrapped_logger formatter if one is present
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
agrare committed Dec 21, 2023
1 parent 310ea27 commit b70a7c0
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
3 changes: 3 additions & 0 deletions lib/vmdb/loggers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion lib/vmdb/loggers/provider_sdk_logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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] "')
Expand All @@ -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

0 comments on commit b70a7c0

Please sign in to comment.