想知道是否有人可以提供一些有关他们使用的日志记录技术的最佳实践,并可能使用airbrake或newrelic或loggly或类似性质的东西来标记某些事件?
例如,假设我有一些事件理论上永远不会影响我的 Controller ,因为它们在前端受到保护 - 就像普通用户能够管理管理员一样。我使用 ruby if 语句阻止这些控件在前端输出。因此,如果我的 Controller 收到这样的请求,那么我就知道要么该代码无法正常工作,要么有人对发送的请求进行了一些黑客攻击。
不管怎样我都想知道。我刚刚发现自己在写:
#TODO: Log this. Either the front end is broken or the user is sending hacked requests
想知道是否有人可以提供一些关于如何处理它的见解,也许使用第三方日志记录工具,也许使用某种标签,我可以使用所述工具设置电子邮件警报?
最佳答案
来自 Airbrake 的摩根在这里。我们没有针对空气制动异常的标记。
使用我们的服务解决此问题的一种方法是从您的 Controller 向 Airbrake 发送自定义错误。
该错误将触发 Airbrake 通知电子邮件,您将收到通知。
例如:
# find me in app/controllers/some_controller.rb
# custom error
class ControllerAccessError < StandardError
end
def action
...
msg = 'front end is broken or the user is sending hacked request'
e = ControllerAccessError.new(msg)
Airbrake.notify_or_ignore(e)
end
以下是有关使用 ruby 手动向 Airbrake 发送错误的更多信息: https://github.com/airbrake/airbrake/wiki/Using-Airbrake-with-plain-Ruby
关于ruby-on-rails - Rails - 使用标签或类型记录事件并获取电子邮件警报 - 最佳实践?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30764677/