custom_logs 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- MWZhMTViMzk2ZGM3OTU3MzdkZTY3NDAxNjFjZGU3ZWU5YzBkODljNg==
4
+ MjliY2M4Mjg4MGEwZjg3MDE2NWM0MmQ3NTIxYmUxYTk1MjM0MDAyOA==
5
5
  data.tar.gz: !binary |-
6
- MzVlZTIwNmZhOGJlNTYwMmRlMjgyNTM2M2QyMzNlMDFjYTU5MzI4Ng==
6
+ MWJjNTU3NjJlYmYwZWZkNWU2ZWYyM2I5YWZlMDgyNWM2MzcxNjQ3NA==
7
7
  SHA512:
8
8
  metadata.gz: !binary |-
9
- MzVkY2Y1N2NlMzI4MzAwODVmMDk4NmVkYWMwY2E3MTBhMWI3MjFkZTI1MmM0
10
- Mjc2Yzk5MDUwMmViYzEyYzE1NDViZDkwZjQ2MjZlZmZhMTY0NDlhMzRhNmRm
11
- ZjU5NGRlNTkyMTc4ZDkyOGY3MzUyYThkMjI3MTRkMTMxNzc2ODM=
9
+ ODc3YzkxYTU0NzgwMTczNzE2MjNlZDlkOTllYTEwMDcyOGEzODg5MjI1Mzll
10
+ MzY4MjJmM2M1N2E5NWYyYjNmZGQ3Njg3NGNkMzk0MjU5YzVlMDg4MmYxN2Q0
11
+ YzZlMjI0ZDA0NTU4OTgyMTVlZjQ2OGJhZjA5ZDdmOTA3YmU4N2I=
12
12
  data.tar.gz: !binary |-
13
- OGNkN2Y1ZDVjMDk0ZTQ1OTE1NjFkNjRmMTgyOTU4MDE1N2FlNGVmNTE0Mzk3
14
- OGY1N2FiMTcxNTYxNmU2NzAxZjI2MmNhZDMyMzVjYzdjNDRkZjIxYzJhZWFm
15
- NTc2NTBmYzc1YzhkMGNmM2EyZGNlOTQ2YzA3OGUxYTE3N2VkYWM=
13
+ ZTBlM2RjMTBmNzU3NDQ3ZTM0ZWY2MWIzYTg5Nzc5NGFiMzZkOTBjZGY4ZTY0
14
+ OTY5NzNmMDdkYzI2NGRjOWQ3YTVjMDgxNzYxOWE3Njk2ZmFlMjdkYTAyMmZi
15
+ YjFjMmZiMjU0YTc0YzU4MDM5MjU5ZjA1ZDFjODAwYzA4OGMwMGM=
@@ -1,6 +1,8 @@
1
1
  module CustomLogs
2
2
  module ActionControllerExt
3
3
 
4
+ protected
5
+
4
6
  def custom_logs
5
7
 
6
8
  original_params = get_original_params
@@ -12,12 +14,18 @@ module CustomLogs
12
14
  logs = {
13
15
  controller: params[:controller],
14
16
  action: params[:action],
15
- email: try_current_user_email,
17
+ current: try_current_user_email,
18
+ path: request.path,
16
19
  params: original_params
17
20
  #flash: original_flash,
18
21
  #response_code: response.status,
19
22
  #response_message: response.message
20
23
  }
24
+
25
+ if request.xhr?
26
+ logs[:ajax] = ajax_attributes
27
+ end
28
+
21
29
  CustomLogs::Logger.write(logs)
22
30
  rescue
23
31
  Rails.logger.info "[CUSTOM LOGS NOT SAVED]: #{logs.to_json}"
@@ -26,10 +34,6 @@ module CustomLogs
26
34
 
27
35
  end
28
36
 
29
- def try_current_user_email
30
- current_user.email rescue ''
31
- end
32
-
33
37
  def get_original_params
34
38
  path_params = request.path_parameters
35
39
  request.params.clone.except(*path_params.keys)
@@ -39,5 +43,22 @@ module CustomLogs
39
43
  request.flash.clone
40
44
  end
41
45
 
46
+ def try_current_user_email
47
+ current = nil
48
+ ParseConfig.get[:user_methods].each do |user_method|
49
+ current = {:"#{user_method.gsub('current_', '')}" => send(user_method).email} rescue nil
50
+ break if current
51
+ end
52
+ current
53
+ end
54
+
55
+ def ajax_attributes
56
+ begin
57
+ {referer: URI::parse(request.headers["HTTP_REFERER"]).path}
58
+ rescue
59
+ {}
60
+ end
61
+ end
62
+
42
63
  end
43
64
  end
@@ -36,7 +36,8 @@ module CustomLogs
36
36
  elsif value.instance_of? Hash
37
37
  new_hash[key] = truncate_hash(value, length, truncate_value)
38
38
  else
39
- new_hash[key] = truncate_value
39
+ # we don't include key when value is not String
40
+ # new_hash[key] = truncate_value
40
41
  end
41
42
  end
42
43
 
@@ -1,3 +1,3 @@
1
1
  module CustomLogs
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -7,4 +7,11 @@ class CustomLogsGenerator < Rails::Generators::Base
7
7
  template "custom_logs.yml", 'config/custom_logs.yml'
8
8
  end
9
9
 
10
+ private
11
+
12
+ def user_methods
13
+ user_methods = ApplicationController.new.methods.select{|m| m.to_s.starts_with?('current_')}
14
+ end
15
+
16
+
10
17
  end
@@ -2,6 +2,10 @@ defaults: &defaults
2
2
  include_params: true
3
3
  truncate_length: 25
4
4
  truncate_value: '[R]'
5
+ user_methods: <%= '[]' if user_methods.empty? %>
6
+ <% user_methods.each do |method| -%>
7
+ <%= " - #{method}" %>
8
+ <% end -%>
5
9
 
6
10
  development:
7
11
  <<: *defaults
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: custom_logs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Marek Piechocki
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-05-14 00:00:00.000000000 Z
11
+ date: 2014-05-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler