lograge 0.3.4 → 0.3.5

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: b0ffc5818b2ecfea5d750c2d0e82ffbfca2114dd
4
- data.tar.gz: 18937487f75539149f07e6f35eadb31b8e8485d4
3
+ metadata.gz: b1b3f1b11217a5fdbe044df974283ba02ba1f105
4
+ data.tar.gz: ab5e62fd370c4772e68119f26cad9f2323bb28bb
5
5
  SHA512:
6
- metadata.gz: ba756dfa89f7112bf6677b1c5be3b495a629e8fec32a10f52c07aec06637c15e63df55d30d33dfc27db3113c9043ddd91c2aa15cc8b26bc439a57b7844b1ef53
7
- data.tar.gz: 2fec943a32467da1728ae77aba093e8e6d8a9fde4b4b7bd3a6b6a07dbe5acc28b7234b4914b43ed486449a81770218666c42ba24107c5325a6e682cc5a76ae9e
6
+ metadata.gz: 015146b24e6e3eb7e67d65b405157b7d2e0835266ab81fbb5bbc5b2a09cfbfd00ee2e515b35eadc7aa8aee08dc148ae222ce167bbd43749e895f5f3f0eee939e
7
+ data.tar.gz: 7b72e262404d7de0ce4e318091e875b6e3337ba006262896e436637d56e9c7de77f1fb69198196bf793e28e5e0a4e111c8abf30b86e0cb88eaadcbf569021440
@@ -29,7 +29,7 @@ module Lograge
29
29
  end
30
30
 
31
31
  def source_field(data)
32
- "#{data[:controller].to_s.gsub('/', '-')}:#{data[:action]}"
32
+ "#{data[:controller].to_s.tr('/', '-')}:#{data[:action]}"
33
33
  end
34
34
  end
35
35
  end
@@ -1,4 +1,5 @@
1
1
  require 'json'
2
+ require 'action_pack'
2
3
  require 'active_support/core_ext/class/attribute'
3
4
  require 'active_support/log_subscriber'
4
5
 
@@ -8,13 +9,7 @@ module Lograge
8
9
  return if Lograge.ignore?(event)
9
10
 
10
11
  payload = event.payload
11
-
12
- data = extract_request(payload)
13
- extract_status(data, payload)
14
- runtimes(data, event)
15
- location(data)
16
- custom_options(data, event)
17
-
12
+ data = extract_request(event, payload)
18
13
  data = before_format(data, payload)
19
14
  formatted_message = Lograge.formatter.call(data)
20
15
  logger.send(Lograge.log_level, formatted_message)
@@ -24,13 +19,28 @@ module Lograge
24
19
  Thread.current[:lograge_location] = event.payload[:location]
25
20
  end
26
21
 
22
+ def unpermitted_parameters(event)
23
+ Thread.current[:lograge_unpermitted_params] ||= []
24
+ Thread.current[:lograge_unpermitted_params].concat(event.payload[:keys])
25
+ end
26
+
27
27
  def logger
28
28
  Lograge.logger.presence || super
29
29
  end
30
30
 
31
31
  private
32
32
 
33
- def extract_request(payload)
33
+ def extract_request(event, payload)
34
+ payload = event.payload
35
+ data = initial_data(payload)
36
+ data.merge!(extract_status(payload))
37
+ data.merge!(extract_runtimes(event, payload))
38
+ data.merge!(extract_location)
39
+ data.merge!(extract_unpermitted_params)
40
+ data.merge!(custom_options(event))
41
+ end
42
+
43
+ def initial_data(payload)
34
44
  {
35
45
  method: payload[:method],
36
46
  path: extract_path(payload),
@@ -56,15 +66,14 @@ module Lograge
56
66
  end
57
67
  end
58
68
 
59
- def extract_status(data, payload)
69
+ def extract_status(payload)
60
70
  if (status = payload[:status])
61
- data[:status] = status.to_i
71
+ { status: status.to_i }
62
72
  elsif (error = payload[:exception])
63
73
  exception, message = error
64
- data[:status] = get_error_status_code(exception)
65
- data[:error] = "#{exception}: #{message}"
74
+ { status: get_error_status_code(exception), error: "#{exception}: #{message}" }
66
75
  else
67
- data[:status] = 0
76
+ { status: 0 }
68
77
  end
69
78
  end
70
79
 
@@ -73,28 +82,35 @@ module Lograge
73
82
  Rack::Utils.status_code(status)
74
83
  end
75
84
 
76
- def custom_options(data, event)
77
- options = Lograge.custom_options(event)
78
- data.merge! options if options
85
+ def custom_options(event)
86
+ Lograge.custom_options(event) || {}
79
87
  end
80
88
 
81
89
  def before_format(data, payload)
82
90
  Lograge.before_format(data, payload)
83
91
  end
84
92
 
85
- def runtimes(data, event)
86
- payload = event.payload
87
- data[:duration] = event.duration.to_f.round(2)
88
- data[:view] = payload[:view_runtime].to_f.round(2) if payload.key?(:view_runtime)
89
- data[:db] = payload[:db_runtime].to_f.round(2) if payload.key?(:db_runtime)
93
+ def extract_runtimes(event, payload)
94
+ data = { duration: event.duration.to_f.round(2) }
95
+ data[:view] = payload[:view_runtime].to_f.round(2) if payload.key?(:view_runtime)
96
+ data[:db] = payload[:db_runtime].to_f.round(2) if payload.key?(:db_runtime)
97
+ data
90
98
  end
91
99
 
92
- def location(data)
100
+ def extract_location
93
101
  location = Thread.current[:lograge_location]
94
- return unless location
102
+ return {} unless location
95
103
 
96
104
  Thread.current[:lograge_location] = nil
97
- data[:location] = location
105
+ { location: location }
106
+ end
107
+
108
+ def extract_unpermitted_params
109
+ unpermitted_params = Thread.current[:lograge_unpermitted_params]
110
+ return {} unless unpermitted_params
111
+
112
+ Thread.current[:lograge_unpermitted_params] = nil
113
+ { unpermitted_params: unpermitted_params }
98
114
  end
99
115
  end
100
116
  end
@@ -1,3 +1,3 @@
1
1
  module Lograge
2
- VERSION = '0.3.4'
2
+ VERSION = '0.3.5'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lograge
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.4
4
+ version: 0.3.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mathias Meyer
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-07-07 00:00:00.000000000 Z
12
+ date: 2015-11-21 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
@@ -25,20 +25,6 @@ dependencies:
25
25
  - - ">="
26
26
  - !ruby/object:Gem::Version
27
27
  version: '0'
28
- - !ruby/object:Gem::Dependency
29
- name: guard-rspec
30
- requirement: !ruby/object:Gem::Requirement
31
- requirements:
32
- - - ">="
33
- - !ruby/object:Gem::Version
34
- version: '0'
35
- type: :development
36
- prerelease: false
37
- version_requirements: !ruby/object:Gem::Requirement
38
- requirements:
39
- - - ">="
40
- - !ruby/object:Gem::Version
41
- version: '0'
42
28
  - !ruby/object:Gem::Dependency
43
29
  name: activesupport
44
30
  requirement: !ruby/object:Gem::Requirement
@@ -128,4 +114,3 @@ signing_key:
128
114
  specification_version: 4
129
115
  summary: Tame Rails' multi-line logging into a single line per request
130
116
  test_files: []
131
- has_rdoc: