ruby-on-rails 删除活动模型序列化器中的日志消息

wdebmtf2  于 2023-04-08  发布在  Ruby
关注(0)|答案(3)|浏览(96)

如何从日志中删除此active-model-serializers消息?
[active_model_serializers] Rendered ActiveModel::Serializer::CollectionSerializer with ActiveModelSerializers::Adapter::JsonApi

5rgfhyps

5rgfhyps1#

在您的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

kqqjbcuj

kqqjbcuj2#

我还没有在AMS配置中找到任何禁用日志的内容,但是,通过重新定义ActiveModelSerializers.logger(源代码),还有其他几种方法可以实现这一点
config/initializers/active_model_serializer.rb中:
1)增加日志级别,以便不记录任何内容:

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


2)将AMS日志写入/dev/null

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

uurv41yg3#

自2018年年中以来,在您的config/initializers/active_model_serializer.rb中执行此操作的正确方法现在是:

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

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

相关问题