Rails 上的 `binding.pry` 时,未知日志打断了我
Unknown logs interrupt me while `binding.pry` on Rails
我正在 Rails 上与 Ruby 一起开发。当我使用 Puma 启动应用程序服务器时,以下日志会每隔几秒继续显示一次。
{"method":{},"path":{},"format":{},"params":{},"controller":"ApplicationCable::Connection","action":"connect","status":200,"duration":8.75,"backtrace":null,"host":null,"user_id":null,"user_type":null,"remote_ip":null,"user_agent":null,"os":null,"os_version":null,"browser":null,"browser_version":null,"@timestamp":"2021-07-28T10:24:34.068Z","@version":"1","message":"[200] (ApplicationCable::Connection#connect)"}
{"method":{},"path":{},"format":{},"params":{},"controller":"ApplicationCable::Connection","action":"disconnect","status":200,"duration":0.58,"backtrace":null,"host":null,"user_id":null,"user_type":null,"remote_ip":null,"user_agent":null,"os":null,"os_version":null,"browser":null,"browser_version":null,"@timestamp":"2021-07-28T10:24:34.069Z","@version":"1","message":"[200] (ApplicationCable::Connection#disconnect)"}
这会中断 binding.pry
提示,所以我无法正确调试应用程序。
[1] pry(#<SomeController>)> {"method":{},"path":{},"format":{},"params":{},"controller":"ApplicationCable::Connection","action":"connect","status":200,"duration":8.75,"backtrace":null,"host":null,"user_id":null,"user_type":null,"remote_ip":null,"user_agent":null,"os":null,"os_version":null,"browser":null,"browser_version":null,"@timestamp":"2021-07-28T10:24:34.068Z","@version":"1","message":"[200] (ApplicationCable::Connection#connect)"}
{"method":{},"path":{},"format":{},"params":{},"controller":"ApplicationCable::Connection","action":"disconnect","status":200,"duration":0.58,"backtrace":null,"host":null,"user_id":null,"user_type":null,"remote_ip":null,"user_agent":null,"os":null,"os_version":null,"browser":null,"browser_version":null,"@timestamp":"2021-07-28T10:24:34.069Z","@version":"1","message":"[200] (ApplicationCable::Connection#disconnect)"}
我无法找到这些日志显示的来源。
我试过的是将 ActionCable.server.config.logger = Logger.new(nil)
添加到 config/application.rb
。但是还是有问题。
https://dev.to/xlts/fixing-rails-action-cable-logger-la8#option-2-try-to-do-it-systematically
我该如何解决这个问题?
提前致谢。
我正在使用 Lograge,所以我通过将以下配置添加到 config/initializers/lograge.rb
来解决这个问题。
Rails.application.configure do
# ...
# ...
# ...
config.lograge.ignore_actions = [
"ApplicationCable::Connection#connect",
"ApplicationCable::Connection#disconnect"
]
end
我正在 Rails 上与 Ruby 一起开发。当我使用 Puma 启动应用程序服务器时,以下日志会每隔几秒继续显示一次。
{"method":{},"path":{},"format":{},"params":{},"controller":"ApplicationCable::Connection","action":"connect","status":200,"duration":8.75,"backtrace":null,"host":null,"user_id":null,"user_type":null,"remote_ip":null,"user_agent":null,"os":null,"os_version":null,"browser":null,"browser_version":null,"@timestamp":"2021-07-28T10:24:34.068Z","@version":"1","message":"[200] (ApplicationCable::Connection#connect)"}
{"method":{},"path":{},"format":{},"params":{},"controller":"ApplicationCable::Connection","action":"disconnect","status":200,"duration":0.58,"backtrace":null,"host":null,"user_id":null,"user_type":null,"remote_ip":null,"user_agent":null,"os":null,"os_version":null,"browser":null,"browser_version":null,"@timestamp":"2021-07-28T10:24:34.069Z","@version":"1","message":"[200] (ApplicationCable::Connection#disconnect)"}
这会中断 binding.pry
提示,所以我无法正确调试应用程序。
[1] pry(#<SomeController>)> {"method":{},"path":{},"format":{},"params":{},"controller":"ApplicationCable::Connection","action":"connect","status":200,"duration":8.75,"backtrace":null,"host":null,"user_id":null,"user_type":null,"remote_ip":null,"user_agent":null,"os":null,"os_version":null,"browser":null,"browser_version":null,"@timestamp":"2021-07-28T10:24:34.068Z","@version":"1","message":"[200] (ApplicationCable::Connection#connect)"}
{"method":{},"path":{},"format":{},"params":{},"controller":"ApplicationCable::Connection","action":"disconnect","status":200,"duration":0.58,"backtrace":null,"host":null,"user_id":null,"user_type":null,"remote_ip":null,"user_agent":null,"os":null,"os_version":null,"browser":null,"browser_version":null,"@timestamp":"2021-07-28T10:24:34.069Z","@version":"1","message":"[200] (ApplicationCable::Connection#disconnect)"}
我无法找到这些日志显示的来源。
我试过的是将 ActionCable.server.config.logger = Logger.new(nil)
添加到 config/application.rb
。但是还是有问题。
https://dev.to/xlts/fixing-rails-action-cable-logger-la8#option-2-try-to-do-it-systematically
我该如何解决这个问题?
提前致谢。
我正在使用 Lograge,所以我通过将以下配置添加到 config/initializers/lograge.rb
来解决这个问题。
Rails.application.configure do
# ...
# ...
# ...
config.lograge.ignore_actions = [
"ApplicationCable::Connection#connect",
"ApplicationCable::Connection#disconnect"
]
end