如何从日志中删除此active-model-serializers消息?[active_model_serializers] Rendered ActiveModel::Serializer::CollectionSerializer with ActiveModelSerializers::Adapter::JsonApi
[active_model_serializers] Rendered ActiveModel::Serializer::CollectionSerializer with ActiveModelSerializers::Adapter::JsonApi
5rgfhyps1#
在您的config/initializers/active_model_serializer.rb中:
config/initializers/active_model_serializer.rb
require 'active_model_serializers' ActiveSupport::Notifications.unsubscribe(ActiveModelSerializers::Logging::RENDER_EVENT)
这将正确地取消订阅渲染事件,而不是仅禁用以下各项的所有日志记录等:https://github.com/rails-api/active_model_serializers/blob/ab98c4a664f26077e5b3c90ea6bcbe129ec2d0b9/docs/general/logging.md
kqqjbcuj2#
我还没有在AMS配置中找到任何禁用日志的内容,但是,通过重新定义ActiveModelSerializers.logger(源代码),还有其他几种方法可以实现这一点在config/initializers/active_model_serializer.rb中:1)增加日志级别,以便不记录任何内容:
ActiveModelSerializers.logger
ActiveModelSerializers.logger.level = Logger::Severity::UNKNOWN
或2)将AMS日志写入/dev/null
/dev/null
ActiveModelSerializers.logger = ActiveSupport::TaggedLogging.new(ActiveSupport::Logger.new('/dev/null'))
uurv41yg3#
自2018年年中以来,在您的config/initializers/active_model_serializer.rb中执行此操作的正确方法现在是:
ActiveModelSerializers.logger = Logger.new(IO::NULL)
参考:https://github.com/rails-api/active_model_serializers/commit/be119b8fcbd6851787ef1b4585eceb1aa7e5316d
3条答案
按热度按时间5rgfhyps1#
在您的
config/initializers/active_model_serializer.rb
中:这将正确地取消订阅渲染事件,而不是仅禁用以下各项的所有日志记录等:https://github.com/rails-api/active_model_serializers/blob/ab98c4a664f26077e5b3c90ea6bcbe129ec2d0b9/docs/general/logging.md
kqqjbcuj2#
我还没有在AMS配置中找到任何禁用日志的内容,但是,通过重新定义
ActiveModelSerializers.logger
(源代码),还有其他几种方法可以实现这一点在
config/initializers/active_model_serializer.rb
中:1)增加日志级别,以便不记录任何内容:
或
2)将AMS日志写入
/dev/null
uurv41yg3#
自2018年年中以来,在您的
config/initializers/active_model_serializer.rb
中执行此操作的正确方法现在是:参考:https://github.com/rails-api/active_model_serializers/commit/be119b8fcbd6851787ef1b4585eceb1aa7e5316d