Skip to content

Attempting to wrap a Logging::Logger in a ActiveSupport::TaggedLogging raises an error #27

@yboulkaid

Description

@yboulkaid

Hi,

ActiveSupport::TaggedLogging is supposed to be able to wrap "any standard Logger object". However, when wrapping an instance of Logging::Logger, this does not work:

ActiveSupport::TaggedLogging.new(Logging::Logger.new(STDOUT))
=> NoMethodError: undefined method `formatter=' for #<Logging::Logger:0x007fa3f98c14d8>

This is because ActiveSupport::TaggedLogging tries to set a formatter in case it doesn't exist.

Since code that tries to wrap the Rails.logger object in a ActiveSupport::TaggedLogging instance is becoming more and more common in the rails ecosystem (cf. here in webpacker), this can be deter many users from using this otherwise good framework.

There is a formatter method already defined in Logging so maybe it could be possible to map formatter= to the MDC feature of Logging?

Also, not sure if this should be part of the logging or the logging-rails repo, it has to do with rails but the RailsCompat module is in the logging repo..

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions