Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

5.2.0 breaks some custom loggers #2700

Closed
tragiclifestories opened this issue Aug 17, 2020 · 9 comments
Closed

5.2.0 breaks some custom loggers #2700

tragiclifestories opened this issue Aug 17, 2020 · 9 comments

Comments

@tragiclifestories
Copy link

We have our own internal logging library that enforces our company standards. It implements #tagged identically to ActiveSupport's TaggedLogging.

Before #1311, webpacker would happily use our custom logger. But that PR flips the if statement, and now Webpacker is messing with our logger, replacing our formatter with some random unwanted one which is incompatible with our gem (we only emit structured JSON logs and handle the lines internally as hashes, so we get no implicit conversion errors instead of log lines).

@gauravtiwari
Copy link
Member

@tragiclifestories sorry about that - lets revert that change 👍

@tragiclifestories
Copy link
Author

Cheers! I think there must be a way to fix the original reported problem without breaking us, but I can't see one just yet.

@gauravtiwari
Copy link
Member

No worries, released 5.2.1

Yes, me neither. Makes sense to revert since it's possible a lot of people might be customising the logger.

// @flippakitten

@gauravtiwari
Copy link
Member

Feel free to close if all good

@tragiclifestories
Copy link
Author

Looks good. Thanks for the quick fix!

@flippakitten
Copy link
Contributor

flippakitten commented Aug 17, 2020

Wow, this PR is a blast from the past.

If my memory serves me correctly, the issue was around centralized logging and when you completely replace the rails logger so when Webpacker initializes it overwrites your logger with a new TaggedLogging instance.

@tragiclifestories Sorry about introducing breaking changes.

@gauravtiwari what about a config option or revert to the current implementation?

  initializer "webpacker.logger" do
    config.after_initialize do
      if ::Rails.logger.respond_to?(:tagged) || use_default_rails_logger
        Webpacker.logger = ::Rails.logger
      else
        Webpacker.logger = ActiveSupport::TaggedLogging.new(::Rails.logger)
      end
    end
  end

EDIT: looking a bit deeper, I do admit my fix was not the best solution.

@scottrobertson
Copy link

What changes happened in 5.2.0? No change log entries.

@gauravtiwari
Copy link
Member

@flippakitten thank you for update. Is it not possible to override Webpacker.logger in the app itself?

@scottrobertson Mainly, dependencies update and some minor fixes: v5.1.1...5-x-stable

@emilkarl
Copy link

emilkarl commented Sep 23, 2020

Reverting this actually breaks it for us when using lograge. Changing it to the other way around works tho. Any idea why?

Edit: Using webpacker 5.2.1 on Rails 5.2.4.4

Error

NoMethodError: undefined method `formatter=' for #<Logging::Logger:0x00007fc0c0edcb18>
web          | Did you mean?  formatter
web          |   /Users/emil/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/activesupport-5.2.4.4/lib/active_support/tagged_logging.rb:63:in `new'
web          |   /Users/emil/.rbenv/versions/2.6.3/lib/ruby/gems/2.6.0/gems/webpacker-5.2.1/lib/webpacker/railtie.rb:34:in `block (2 levels) in <class:Engine>'

This change make it work 🤷‍♂️

initializer "webpacker.logger" do
  config.after_initialize do
    if ::Rails.logger.respond_to?(:tagged)
      Webpacker.logger = ActiveSupport::TaggedLogging.new(::Rails.logger)
    else
      Webpacker.logger = ::Rails.logger
    end
  end
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants