簡體   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