我们的Rails日志中充满了来自负载均衡器的状态页,过滤掉它们将是很棒的。
我们希望记录所有其他端点,但我们希望能够单独关闭该控制器的应用程序日志记录。
控制器如下所示:
class V2::StatusController < ApplicationController
skip_before_filter :authenticate
def ping
head :ok, text: 'OK'
end
end
编辑:我们的日志设置为发送到Loggly:
require 'syslogger'
config.logger = Syslogger.new("APP_NAME", Syslog::LOG_PID, Syslog::LOG_LOCAL7)
config.lograge.enabled = true
config.lograge.formatter = Lograge::Formatters::Json.new
发布于 2015-10-20 19:56:16
由于您使用的是洛格里奇,这是lograge的README中关于如何忽略操作的内容:
为了进一步清理日志记录,您还可以告诉Lograge跳过符合给定条件的日志消息。可以跳过从某些控制器操作生成的日志消息,也可以编写自定义处理程序,根据日志事件中的数据跳过消息:
# config/environments/production.rb
MyApp::Application.configure do
config.lograge.enabled = true
config.lograge.ignore_actions = ['home#index', 'aController#anAction']
config.lograge.ignore_custom = lambda do |event|
# return true here if you want to ignore based on the event
end
end
所以你的特别是
config.logger = Syslogger.new("APP_NAME", Syslog::LOG_PID, Syslog::LOG_LOCAL7)
config.lograge.enabled = true
config.lograge.formatter = Lograge::Formatters::Json.new
config.lograge.ignore_actions = ["v2/status#ping", ...]
https://stackoverflow.com/questions/33245328
复制相似问题