25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/td/logger/agent/rails/model.rb', line 25
def td_enable_model_tracer(tag, options={})
only = nil
except = nil
static = {}
if o = options[:only]
only = case o
when Array
o
else
[o]
end.map {|e| e.to_s }
end
if o = options[:except]
except = case o
when Array
o
else
[o]
end.map {|e| e.to_s }
end
if o = options[:static]
o.each_pair {|k,v|
static[k.to_s] = v
}
end
if defined?(after_commit)
m = :after_commit
else
m = :after_save
end
__send__(m) do |record|
data = {}
record.attribute_names.each {|name|
name = name.to_s
if (!only || only.include?(name)) && (!except || !except.include?(name))
data[name] = record.read_attribute(name)
end
}
static.each_pair {|k,v|
data[k] = v
}
time = data['updated_at']
if time.is_a?(Time)
data.delete('updated_at')
else
time = Time.now
end
TreasureData::Logger.post_with_time(tag, data, time)
end
end
|