ActionView::Template::Error (undefined method `silence' for)
Asked Answered
M

1

6

I have very strange problem on heroku. I have view that looks like this:

= content_for :header_title do
  = t('.header_title')

- if @appointments.exists?
  %table.table.table-striped.table-bordered.table-hover
    %thead
      %tr
        %th= t('.id')
        %th= t('.athena_health_id')
        %th= t('.start_time')
        %th= t('.duration')
        %th= t('.provider')
        %th= t('.created_at')
        %th= t('.updated_at')
    %tbody
      = render @appointments

  = paginate @appointments
- else
  %h3.text-center= t('.appointments_not_found')
%hr/

Nothing special. When I visit page that is using this template on heroku i receive:

 ActionView::Template::Error (undefined method `silence' for #<Logger:0x007f7a86267a70>):

Spec are passing. On my local everything is working fine. I don't know what is going on. Stacktrace is showing that the problem is following line:

= paginate @appointments

I'm using Rails 5.0 and kaminari (1.0.0.alpha). Any ideas?

Edit: In my production.rb I have:

  if ENV['RAILS_LOG_TO_STDOUT'].present?
    config.logger = ActiveSupport::TaggedLogging.new(Logger.new(STDOUT))
  end

config.log_formatter = ::Logger::Formatter.new
Menado answered 13/7, 2016 at 19:19 Comment(3)
The error seems unable to find "silence" method for a class called Logger. Does your code have a Logger class or is that on Heroku's end?Circle
No, my class does not have logger class. In production.rb I have also: if ENV['RAILS_LOG_TO_STDOUT'].present? config.logger = ActiveSupport::TaggedLogging.new(Logger.new(STDOUT)) end config.log_formatter = ::Logger::Formatter.newPorta
Do you have seen this issue on github? silence method of ::Logger class was deprecated since Rails4.2 and it was removed from Rails5.Brandes
B
12

In Rails5 silence method was removed from the ::Logger base class (see this issue)

So instead to pass a ::Logger instance, try to pass an ActiveSupport::Logger instance which expose the silence method (see documentation), like this:

config.logger = ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT))

note: ActiveSupport::Logger inherit from the ::Logger base class and include LoggerSilence module (see documentation)

An example from my rails console (rails5 and ruby2.3.0)

logger = ActiveSupport::TaggedLogging.new(Logger.new(STDOUT))
 => #<Logger:0x007f890b8a3d10 @progname=nil, @level=0, @default_formatter=#<Logger::Formatter:0x007f890b8a2cd0 @datetime_format=nil>, @formatter=#<ActiveSupport::Logger::SimpleFormatter:0x007f890b8a26e0 @datetime_format=nil>, @logdev=#<Logger::LogDevice:0x007f890b8a2870 @shift_size=nil, @shift_age=nil, @filename=nil, @dev=#<IO:<STDOUT>>, @mon_owner=nil, @mon_count=0, @mon_mutex=#<Thread::Mutex:0x007f890b8a2730>>> 
logger.silence
NoMethodError: undefined method `silence' for #<Logger:0x007f890b8a3d10>
# ...

logger = ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new(STDOUT))
 => #<ActiveSupport::Logger:0x007f890bd2a028 @progname=nil, @level=0, @default_formatter=#<Logger::Formatter:0x007f890bd29fb0 @datetime_format=nil>, @formatter=#<ActiveSupport::Logger::SimpleFormatter:0x007f890bd29f10 @datetime_format=nil>, @logdev=#<Logger::LogDevice:0x007f890bd29f60 @shift_size=nil, @shift_age=nil, @filename=nil, @dev=#<IO:<STDOUT>>, @mon_owner=nil, @mon_count=0, @mon_mutex=#<Thread::Mutex:0x007f890bd29f38>>, @local_levels=#<Concurrent::Map:0x007f890bd29ec0 entries=0 default_proc=nil>> 
logger.silence
LocalJumpError: no block given (yield)
# The method exists, but I don't pass any block
Brandes answered 13/7, 2016 at 20:28 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.