ManageIQ / manageiq-automation_engine

Automation engine for ManageIQ
Apache License 2.0
11 stars 73 forks source link

Fix logger when wrapped in a container/journald logger #521

Closed Fryguy closed 1 year ago

Fryguy commented 1 year ago

The wrapped container/journald logger from core uses ActiveSupport::Logger.broadcast and then changes the underlying logger to have a nil logdev. This has the effect of writing to the wrapped logger and avoiding writing to the underlying file. However, in the case of this automation logger, we still want to write to the database, so we still need that underlying logger to execute the database part, but not the file part.

There is an added complication that ActiveSupport::Logger.broadcast fronts the add method, but doesn't support kwargs. Prior to this commit, we used kwargs to pass around the request_id, however, the broadcast would ignore those, instead sending them as a fourth paramater to the container loggers add method, which doesn't known about that extra parameter. To fix that issue, this commit instead creates a new method responsible for writing to the db, and then info, debug, etc will call that first before calling the original add method with the expected number of parameters.

@jrafanie Please review.

miq-bot commented 1 year ago

Checked commit https://github.com/Fryguy/manageiq-automation_engine/commit/f98b0fb33c2a80300ef20ef18c6bfbd5a34b52ff with ruby 2.6.10, rubocop 1.28.2, haml-lint 0.35.0, and yamllint 2 files checked, 6 offenses detected

lib/manageiq/automation_engine/logger.rb