Mateusz Urbański Mateusz Urbański - 1 year ago 168
Ruby Question

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

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?
%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')
= render @appointments

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

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?

In my production.rb I have:

if ENV['RAILS_LOG_TO_STDOUT'].present?
config.logger =

config.log_formatter =

Answer Source

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 =

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 =
 => #<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>>> 
NoMethodError: undefined method `silence' for #<Logger:0x007f890b8a3d10>
# ...

logger =
 => #<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>> 
LocalJumpError: no block given (yield)
# The method exists, but I don't pass any block
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download