rack-action_logger 0.1.8 → 0.1.9

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fd9926ff15cdf99768758b6946e374ea48f42fce
4
- data.tar.gz: f736d95165fadbb43eaddf0dfa25f23d3898db53
3
+ metadata.gz: 22b077d4a3c2233f2cc7ad125f6327a38097439c
4
+ data.tar.gz: 7afbcbfe31b62c9062529e271038d432527c271e
5
5
  SHA512:
6
- metadata.gz: 8833c6e2df55310fc9cfa311bdb161300864e4ab967b9361eb65d875a940f6de6ab6cdc7077e3ecb969aa4849e7873c8465876509af1b6bea5daca5f5ce4ffbb
7
- data.tar.gz: ede7423c9b93e464c9585babb93cde6d81130dba15b2434fbaf5d9c6cd5ef0ecfebad8064bc71b4edd8d85456f0451ae5b17d034bd50e337da95b823261bc04c
6
+ metadata.gz: 294f9871ddd3695e7b1f3bfff2583029172a3e9ac45384901b3120ebb38881be1a97a07ecbf91a2d46f5c10150ac610cbc4784050af5ac2cdb6b930380c9ad59
7
+ data.tar.gz: 2e90f1d3f4abdb0024203c4fc4041c8c8b629f61f4930d4beb51948fb593a3a01766bdff2a970ea6e09ff44e217c6f693edd93852d40e4c3a3750d2c347b049c
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rack-action_logger (0.1.8)
4
+ rack-action_logger (0.1.9)
5
5
  activesupport
6
6
  fluent-logger (~> 0.5)
7
7
  woothee (~> 1.4)
data/README.md CHANGED
@@ -69,6 +69,24 @@ It is intended to collect user request log, action log and any other custome log
69
69
 
70
70
  Under example folder, there are sample Rails applications to see how these sample logs are created.
71
71
 
72
+ ### Model log
73
+
74
+ ```json
75
+ {
76
+ "message": {
77
+ "user_id": null,
78
+ "request_id": "5aae4cc6-125b-4049-b555-502d6968e041",
79
+ "_method": "update",
80
+ "_after:updated_at": "2016-11-18 18:40:15 +0900",
81
+ "_before:updated_at": "2016-11-18 18:33:56 +0900",
82
+ "_after:views": 96,
83
+ "_before:views": 95,
84
+ "tag": "action.model_articles"
85
+ },
86
+ "tag": "action.model_articles"
87
+ }
88
+ ```
89
+
72
90
  ## Installation
73
91
 
74
92
  Add this line to your rails application's Gemfile:
@@ -16,6 +16,7 @@ module Rack::ActionLogger
16
16
  self.class.column_names.each do |column_name|
17
17
  record["_#{column_name}"] = self.try(column_name)
18
18
  end
19
+ record = Rack::ActionLogger::ParameterFiltering.apply_filter(record)
19
20
  Rack::ActionLogger::Container.set_append_log(record, "model_#{self.class.table_name}")
20
21
  end
21
22
 
@@ -29,6 +30,7 @@ module Rack::ActionLogger
29
30
  record["_before:#{column_name}"] = self.try("#{column_name}_was")
30
31
  end
31
32
  end
33
+ record = Rack::ActionLogger::ParameterFiltering.apply_filter(record)
32
34
  Rack::ActionLogger::Container.set_append_log(record, "model_#{self.class.table_name}")
33
35
  end
34
36
 
@@ -39,6 +41,7 @@ module Rack::ActionLogger
39
41
  record["_#{column_name}"] = self.try(column_name)
40
42
  end
41
43
  end
44
+ record = Rack::ActionLogger::ParameterFiltering.apply_filter(record)
42
45
  Rack::ActionLogger::Container.set_append_log(record, "model_#{self.class.table_name}")
43
46
  end
44
47
  end
@@ -7,9 +7,6 @@ module Rack::ActionLogger
7
7
  EXPORT_KEYS = [:rack_action_logger_attributes]
8
8
 
9
9
  class << self
10
- def store
11
- Thread.current[THREAD_KEY] ||= {}
12
- end
13
10
 
14
11
  def clear
15
12
  Thread.current[THREAD_KEY] = nil
@@ -72,6 +69,10 @@ module Rack::ActionLogger
72
69
 
73
70
  private
74
71
 
72
+ def store
73
+ Thread.current[THREAD_KEY] ||= {}
74
+ end
75
+
75
76
  def is_valid_hash(hash)
76
77
  if hash.is_a? Hash
77
78
  true
@@ -21,8 +21,6 @@ module Rack::ActionLogger::Metrics
21
21
  @request = Rack::Request.new(env)
22
22
  @response = Rack::Response.new(body, status_code, headers)
23
23
  @ua = Woothee.parse(@request.user_agent)
24
- filters = Rack::ActionLogger.configuration.filters
25
- @compiled_filters = Rack::ActionLogger::ParameterFiltering.compile(filters)
26
24
  end
27
25
 
28
26
  def tag_suffix
@@ -53,7 +51,7 @@ module Rack::ActionLogger::Metrics
53
51
  end
54
52
 
55
53
  def params
56
- Rack::ActionLogger::ParameterFiltering.apply_filter(@request.params, @compiled_filters)
54
+ Rack::ActionLogger::ParameterFiltering.apply_filter(@request.params)
57
55
  end
58
56
 
59
57
  def request_headers
@@ -108,7 +106,7 @@ module Rack::ActionLogger::Metrics
108
106
  response_bodies = []
109
107
  @body.each { |part| response_bodies << part } if @body
110
108
  result = JSON.parse(response_bodies.join('')) rescue {}
111
- Rack::ActionLogger::ParameterFiltering.apply_filter(result, @compiled_filters)
109
+ Rack::ActionLogger::ParameterFiltering.apply_filter(result)
112
110
  end
113
111
  end
114
112
  end
@@ -4,16 +4,16 @@ module Rack::ActionLogger
4
4
 
5
5
  class << self
6
6
 
7
- def apply_filter(original_params, compiled_filters)
7
+ def apply_filter(original_params)
8
8
  filtered_params = {}
9
9
 
10
10
  original_params.each do |key, value|
11
11
  if compiled_filters.any? { |r| key =~ r }
12
12
  value = FILTERED
13
13
  elsif value.is_a?(Hash)
14
- value = apply_filter(value, compiled_filters)
14
+ value = apply_filter(value)
15
15
  elsif value.is_a?(Array)
16
- value = value.map { |v| v.is_a?(Hash) ? apply_filter(v, compiled_filters) : v }
16
+ value = value.map { |v| v.is_a?(Hash) ? apply_filter(v) : v }
17
17
  end
18
18
 
19
19
  filtered_params[key] = value
@@ -22,10 +22,17 @@ module Rack::ActionLogger
22
22
  filtered_params
23
23
  end
24
24
 
25
+ private
26
+
27
+ def compiled_filters
28
+ @compiled_filters ||= compile(Rack::ActionLogger.configuration.filters)
29
+ end
30
+
25
31
  def compile(filters)
26
32
  filter_strings = filters.map(&:to_s)
27
33
  filter_strings.map { |item| Regexp.compile(Regexp.escape(item)) }
28
34
  end
35
+
29
36
  end
30
37
  end
31
38
  end
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  module ActionLogger
3
- VERSION = '0.1.8'
3
+ VERSION = '0.1.9'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-action_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.8
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Koichi Ishida
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-11-18 00:00:00.000000000 Z
11
+ date: 2016-11-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport