2

Wondering if someone could offer some best practice on logging techniques they use and maybe tagging certain events using airbrake or newrelic or loggly, or something of that nature?

For example, lets say I have events that should never hit my controller in theory, because they are protected on the front end - like a regular user being able to manage an admin. I prevent these controls from being outputted on the front end using ruby if statements. So if my controller gets hit with a request like this, then I know that either that code isn't working right, or someone is doing some hacking with the request being sent.

Either way I want to know. I just found myself writing:

#TODO: Log this. Either the front end is broken or the user is sending hacked requests

Wondering if anyone can offer some insight as to how they handle it, maybe with a third party logging tool, maybe with some sort of tag that I could set up email alerts with said tool?

4

2 回答 2

3

来自 Airbrake 的摩根在这里。我们没有针对 Airbrake Exceptions 的标签。

使用我们的服务解决此问题的一种方法是从您的控制器向 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

于 2015-06-10T21:04:00.317 回答
2

来自 Loggly 的 Jason。您还可以设置一个新的 Logger,然后记录您喜欢的任何内容。它使用纯 Ruby 代码,没有任何专有库。例如:

logger.warn("Regular user should not have access")

更好的是,您可以使用 JSON 字段来轻松进行报告和过滤。我不是 Ruby 程序员,但我认为它看起来像这样?

logger.warn({:username => username, :type => "Access Violation", :message => "Regular user should not have access"}.to_json);

在 Loggly 中,您可以设置在收到与此搜索匹配的消息时通过电子邮件发送的警报

 json.type:"Access Violation"
于 2015-06-11T16:41:15.197 回答