onelinejson 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -38,13 +38,19 @@ It has the following top level entries: `request`, `response` and `debug_info`.
38
38
 
39
39
  Add this line to your application's Gemfile:
40
40
 
41
- gem "lograge", git: "git@github.com:i0rek/lograge.git", branch: "config_subscriber"
42
- gem 'onelinejson'
41
+ ```
42
+ group :production do
43
+ gem "lograge", git: "git@github.com:i0rek/lograge.git", branch: "before_format"
44
+ gem 'onelinejson'
45
+ end
46
+ ```
43
47
 
44
48
  You need my lograge repo for now, until my PR got merged which I hope will happen eventually.
45
49
  And then execute:
46
50
 
47
- $ bundle
51
+ ```
52
+ $ bundle
53
+ ```
48
54
 
49
55
  ## Contributing
50
56
 
@@ -1,3 +1,3 @@
1
1
  module Onelinejson
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
data/lib/onelinejson.rb CHANGED
@@ -13,20 +13,24 @@ module Onelinejson
13
13
  request.headers.env
14
14
  elsif request.headers.respond_to?(:to_hash)
15
15
  request.headers.to_hash
16
- end.reject {|k, v| !k.starts_with?("HTTP_") || k == "HTTP_AUTHORIZATION"}
16
+ end.reject do |k, v|
17
+ !k.starts_with?("HTTP_") || k == "HTTP_AUTHORIZATION"
18
+ end
19
+ parameters = params.reject do |k,v|
20
+ k == 'controller' ||
21
+ k == 'action' ||
22
+ v.is_a?(ActionDispatch::Http::UploadedFile)
23
+ end
17
24
 
18
25
  payload[:request] = {
19
- params: params.reject { |k,v|
20
- k == 'controller' || k == 'action' || v.is_a?(ActionDispatch::Http::UploadedFile)
21
- },
26
+ params: parameters,
22
27
  headers: headers,
23
28
  ip: request.ip,
24
29
  uuid: request.env['action_dispatch.request_id'],
25
30
  controller: self.class.name,
26
31
  date: Time.now.utc.iso8601,
27
32
  }
28
- payload[:request][:user_id] = current_user.id if defined?(current_user) && current_user
29
-
33
+ payload[:request][:user_id] = @current_user_id || (@current_user && @current_user.id)
30
34
  end
31
35
  end
32
36
 
@@ -35,19 +39,19 @@ module Onelinejson
35
39
  config.lograge.formatter = ::Lograge::Formatters::Json.new
36
40
  config.lograge.enabled = true
37
41
  config.lograge.before_format = lambda do |data, payload|
38
- data.merge(payload)
39
- request = payload[:request].merge(data.select{ |k,_|
42
+ request = data.select{ |k,_|
40
43
  [:method, :path, :format, :controller, :action].include?(k)
41
- })
44
+ }.merge(payload[:request])
42
45
  response = data.select{ |k,_|
43
46
  [:status, :duration, :view, :view_runtime].include?(k)
44
47
  }
45
- Hash[{
48
+ {
49
+ debug_info: payload[:debug_info] || {},
46
50
  request: request,
47
51
  response: response,
48
- debug_info: payload[:debug_info]
49
- }.sort]
52
+ }
50
53
  end
54
+
51
55
  ActiveSupport.on_load(:action_controller) do
52
56
  include AppControllerMethods
53
57
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: onelinejson
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-11-20 00:00:00.000000000 Z
12
+ date: 2013-11-28 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: lograge