log_method 1.0.0 → 1.1.0

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
  SHA256:
3
- metadata.gz: aaf9e766e7cd25359757ba13ccb52a0f21452c835025dde17e58a2ec1591c311
4
- data.tar.gz: ec61724f38c1f35ce76747cd5f3b9f21c0f775b76e4bfd43bcf76d8cf01c9318
3
+ metadata.gz: dd51e1c0b040a4cc45e4d687d5d856f2e7bccec8b3abc9a7805d7e8eb3e5488e
4
+ data.tar.gz: 0bf8d484eb418695b4b3ce546bda78bb033124b0e9c950714cb14f90c6217815
5
5
  SHA512:
6
- metadata.gz: b6d1a643280ce11e2502d364da9d15c1f9032eb0b7ed81f8c70cc2431fe1113a9a8c05447e1590e308271705ea3db5a5d847982281e4e9a6c99caae06a3abe73
7
- data.tar.gz: cca740859bfed322dc5762b7190b743bdcff095f12d82a9541c9e27544243a4c90295b5d16f5f0116cf68d09dd17a3e393a25c530240329b54cc9c2c020d9769
6
+ metadata.gz: 3c3eb39b6bdce35dc03780555480f9e2e7ac33b0c1464b35ee0e1ba6f79ea7805cd19fee8e618b4a4b8ca044e4f82029ef943d2e13c61d10deaa77e2b04d94c4
7
+ data.tar.gz: 74ceee8774b9f583dc0df50b341f4aa1f363672c3ad605e318ff736319e84b6375a164ceeceedbcd27e2e8f8dbf4ace63b5c3d23a1c6273107f314a57466454b
data/README.md CHANGED
@@ -100,7 +100,7 @@ LogMethod.config do |c|
100
100
  c.external_identifier_method = :external_id
101
101
  c.current_actor_proc = ->() { PaperTrail.request.whodunnit }
102
102
  c.current_actor_id_label = "user_id"
103
- c.after_log_proc = ->(class_thats_logging_name, method_name, object_id, object_class_name, trace_id, current_actor_id) {
103
+ c.after_log_proc = ->(class_thats_logging_name, method_name, object_id, object_class_name, trace_id, current_actor_id, log_message) {
104
104
  Bugsnag.leave_breadcrumb method_name.to_s[0..29], {
105
105
  class: class_thats_logging_name,
106
106
  object_id: object_id,
@@ -115,13 +115,14 @@ end
115
115
 
116
116
  ### Options
117
117
 
118
- * `after_log_proc` This is a proc/lambda to be called after each log message has been sent to `Rails.logger.info`. In the example above, we're using this to send a breadcrumb to Bugsnag so that if there is an error with this request, we can see what log messages were logged for that request. It will be given these arguments:
118
+ * `after_log_proc` This is a proc/lambda to be called after each log message has been sent to `Rails.logger.info`. In the example above, we're using this to send a breadcrumb to Bugsnag so that if there is an error with this request, we can see what log messages were logged for that request. It will be given these arguments and it must accept and require all 7 or none will be passed:
119
119
  - `class_thats_logging_name` - The class where `log` was called
120
120
  - `method_name` - The method name passed to `log`
121
121
  - `object_id` - The id of the object passed to `log`, if it had one
122
122
  - `object_class_name` - The class name of the object passed to log, if one was passed
123
123
  - `trace_id` - The trace id returned by `trace_id_proc`, or `nil` if that isn't configured.
124
124
  - `current_actor_id` - The value returned by; `current_actor_proc`, or `nil` if that isn't configured.
125
+ - `log_message` - the log message passed to `log`
125
126
  * `current_actor_id_label` - If a current actor is logged, this is the label that will precede it in the logs
126
127
  * `current_actor_proc` - Called to retrieve an identifier of the current actor executing the code, such as the current user.
127
128
  * `external_identifier_method` - If you are using external ids on your objects, this is the name of that method. If an object is passed in that responds to this method, it will be used instead of `id` when creating the log message.
@@ -1,5 +1,5 @@
1
1
  class LogMethod::BugsnagAfterLog
2
- def self.call(class_thats_logging_name, method_name, object_id, object_class_name, trace_id, current_actor_id)
2
+ def self.call(class_thats_logging_name, method_name, object_id, object_class_name, trace_id, current_actor_id, _log_message)
3
3
  Bugsnag.leave_breadcrumb method_name.to_s[0..29], {
4
4
  class: class_thats_logging_name,
5
5
  object_id: object_id,
@@ -8,29 +8,44 @@ module LogMethod::Log
8
8
  trace_id = LogMethod.config.trace_id_proc.()
9
9
  current_actor_id = LogMethod.config.current_actor_proc.()
10
10
 
11
- message = if message.nil?
12
- message_or_object
13
- else
14
- object_id,object_class = if !logging_external_identifier_method.nil? &&
15
- message_or_object.respond_to?(logging_external_identifier_method)
11
+ object_identifier_phrase = ""
16
12
 
17
- [message_or_object.send(logging_external_identifier_method), message_or_object.class]
13
+ if message.nil?
14
+ message = message_or_object
15
+ else
16
+ object_id,object_class = if !logging_external_identifier_method.nil? &&
17
+ message_or_object.respond_to?(logging_external_identifier_method)
18
18
 
19
- elsif message_or_object.kind_of?(ActiveRecord::Base)
19
+ [message_or_object.send(logging_external_identifier_method), message_or_object.class]
20
20
 
21
- [message_or_object.id, message_or_object.class]
21
+ elsif message_or_object.kind_of?(ActiveRecord::Base)
22
22
 
23
- else
23
+ [message_or_object.id, message_or_object.class]
24
24
 
25
- [message_or_object.inspect, message_or_object.class]
25
+ else
26
26
 
27
- end
28
- "[#{object_class}/#{object_id}]: #{message}"
29
- end
27
+ [message_or_object.inspect, message_or_object.class]
30
28
 
31
- Rails.logger.info("[#{self.class}##{method}](via LogMethod::Log)#{format_trace_id(trace_id)}#{format_current_actor_id(current_actor_id)}: #{message}")
29
+ end
30
+ object_identifier_phrase = "[#{object_class}/#{object_id}]: "
31
+ end
32
32
 
33
- LogMethod.config.after_log_proc.(self.class.name, method, object_id, object_class&.name, trace_id, current_actor_id)
33
+ Rails.logger.info("[#{self.class}##{method}](via LogMethod::Log)#{format_trace_id(trace_id)}#{format_current_actor_id(current_actor_id)}: #{object_identifier_phrase}#{message}")
34
+
35
+ all_args = [self.class.name, method, object_id, object_class&.name, trace_id, current_actor_id, message]
36
+
37
+ after_log_proc = LogMethod.config.after_log_proc
38
+ arity = if after_log_proc.kind_of?(Proc)
39
+ after_log_proc.arity
40
+ elsif after_log_proc.respond_to?(:call)
41
+ after_log_proc.method(:call).arity
42
+ end
43
+ args_for_arity = if arity <= 0
44
+ []
45
+ else
46
+ all_args[0..(arity-1)]
47
+ end
48
+ after_log_proc.(*args_for_arity)
34
49
  end
35
50
 
36
51
  private
@@ -1,3 +1,3 @@
1
1
  module LogMethod
2
- VERSION="1.0.0"
2
+ VERSION="1.1.0"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: log_method
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dave Copeland
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-11-30 00:00:00.000000000 Z
11
+ date: 2021-12-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -38,7 +38,7 @@ dependencies:
38
38
  - - ">="
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
- description:
41
+ description:
42
42
  email:
43
43
  - davec@naildrivin5.com
44
44
  executables: []
@@ -73,7 +73,7 @@ metadata:
73
73
  homepage_uri: https://github.com/sustainable-rails/log_method
74
74
  source_code_uri: https://github.com/sustainable-rails/log_method
75
75
  changelog_uri: https://github.com/sustainable-rails/log_method/releases
76
- post_install_message:
76
+ post_install_message:
77
77
  rdoc_options: []
78
78
  require_paths:
79
79
  - lib
@@ -88,8 +88,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
88
88
  - !ruby/object:Gem::Version
89
89
  version: '0'
90
90
  requirements: []
91
- rubygems_version: 3.0.3
92
- signing_key:
91
+ rubygems_version: 3.2.29
92
+ signing_key:
93
93
  specification_version: 4
94
94
  summary: A nice log method for your Rails app that provides a ton of useful context
95
95
  in each message!