繁体   English   中英

使用Librato记录对模型的更改

[英]Log changes to a model with Librato

我有一个Devise模型:

class Account < ActiveRecord::Base
  devise ::trackable

我想查看在Librato中创建和登录Account的次数。

使用Librato的日志流解析,您可以使用$stdout.puts记录事件。

我建议提取此日志以解决问题 ,并使用模型回调来监视更改。

我们可以在lib/librato/account.rb创建一个文件:

module Librato
  module Account
    extend ActiveSupport::Concern

    included do
      after_create do
        $stdout.puts 'count#account.create=1'
      end

      after_save if: :current_sign_in_at_changed? do
        $stdout.puts 'count#account.sign_in=1'
      end
    end
  end
end

然后将其包含在模型中,因此:

class Account < ActiveRecord::Base
  include Librato::Account

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM