user7330717
user7330717

Reputation:

Remove log message in active-model-serializers

How can I remove this active-model-serializers message from my logs?

[active_model_serializers] Rendered ActiveModel::Serializer::CollectionSerializer with ActiveModelSerializers::Adapter::JsonApi

Upvotes: 6

Views: 2488

Answers (3)

Mofe Ejegi
Mofe Ejegi

Reputation: 1083

Since mid-2018, the correct way to do this is in your config/initializers/active_model_serializer.rb is now:

ActiveModelSerializers.logger = Logger.new(IO::NULL)

Reference: https://github.com/rails-api/active_model_serializers/commit/be119b8fcbd6851787ef1b4585eceb1aa7e5316d

Upvotes: 0

RandallB
RandallB

Reputation: 5575

In your config/initializers/active_model_serializer.rb:

require 'active_model_serializers'
ActiveSupport::Notifications.unsubscribe(ActiveModelSerializers::Logging::RENDER_EVENT)

This properly unsubscribes you from the rendering event, as opposed to just disabling all logging, etc. from: https://github.com/rails-api/active_model_serializers/blob/ab98c4a664f26077e5b3c90ea6bcbe129ec2d0b9/docs/general/logging.md

Upvotes: 11

Slava.K
Slava.K

Reputation: 3080

I haven't found anything in AMS configuration to disable logs, however, there are several other ways of achieving this by redefining ActiveModelSerializers.logger (source)

in your config/initializers/active_model_serializer.rb:

1) Increase the log level so that nothing will get logged:

ActiveModelSerializers.logger.level = Logger::Severity::UNKNOWN

or

2) Write AMS log to /dev/null

ActiveModelSerializers.logger = ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new('/dev/null'))

Upvotes: 1

Related Questions