debug_logging 3.1.9 → 4.0.1

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.
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  require "active_support"
4
2
  require "active_support/log_subscriber"
5
3
 
@@ -34,8 +32,8 @@ module DebugLogging
34
32
  {
35
33
  name: event.name,
36
34
  duration: Rational(event.duration, 1000).to_f,
37
- time: debug_time_to_s(event.time),
38
- end: debug_time_to_s(event.end),
35
+ time: debug_event_time_to_s(event.time),
36
+ end: debug_event_time_to_s(event.end),
39
37
  args: debug_signature_to_s(args: args, config_proxy: config_proxy),
40
38
  payload: debug_payload_to_s(payload: payload, config_proxy: config_proxy),
41
39
  }
@@ -2,6 +2,20 @@ module DebugLogging
2
2
  module Util
3
3
  module_function
4
4
 
5
+ def debug_time(time_or_monotonic)
6
+ case time_or_monotonic
7
+ when Time, DateTime
8
+ time_or_monotonic
9
+ when Numeric
10
+ Time.at(time_or_monotonic)
11
+ when String
12
+ Time.parse(time_or_monotonic)
13
+ else
14
+ # Garbage in, Sweet Nourishing Gruel Out
15
+ Time.now
16
+ end
17
+ end
18
+
5
19
  # methods_to_log may be an array of a single method name, followed by config options and payload,
6
20
  # or it could be an array of method names followed by config options and payload to be shared by the whole set.
7
21
  def extract_payload_and_config(method_names:, payload: nil, config: nil)
@@ -14,6 +28,7 @@ module DebugLogging
14
28
  scoped_payload
15
29
  end
16
30
  config_opts = config&.clone(freeze: false) || {}
31
+ # puts "[EPAC] config: #{config}, scoped_payload: #{scoped_payload}, payload: #{payload}, config_opts: #{config_opts}"
17
32
  unless payload.empty?
18
33
  DebugLogging::Configuration::CONFIG_KEYS.each { |k| config_opts[k] = payload.delete(k) if payload.key?(k) }
19
34
  end
@@ -35,6 +50,8 @@ module DebugLogging
35
50
  # logged :meth1, :meth2, :meth3 without options is valid
36
51
  method_names
37
52
  end
53
+ else
54
+ raise ArgumentError, "unknown type for method_names: #{method_names.class}"
38
55
  end
39
56
  [method_names, payload, config_opts]
40
57
  end
@@ -1,7 +1,5 @@
1
- # frozen_string_literal: true
2
-
3
1
  module DebugLogging
4
2
  module Version
5
- VERSION = "3.1.9"
3
+ VERSION = "4.0.1"
6
4
  end
7
5
  end
data/lib/debug_logging.rb CHANGED
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  # Std Lib
4
2
  require "logger"
5
3
  require "digest"
@@ -44,7 +42,8 @@ require "debug_logging/class_logger"
44
42
  #
45
43
  # # For instance methods:
46
44
  # # Option 1: specify the exact method(s) to add logging to
47
- # include DebugLogging::InstanceLogger.new(i_methods: [:drive, :stop])
45
+ # extend DebugLogging::InstanceLogger
46
+ # i_logged [:drive, :stop]
48
47
  #
49
48
  # # Provides the `logged` method decorator
50
49
  # extend DebugLogging::ClassLogger
@@ -59,7 +58,8 @@ require "debug_logging/class_logger"
59
58
  #
60
59
  # # For instance methods:
61
60
  # # Option 2: add logging to all instance methods defined above (but *not* defined below)
62
- # include DebugLogging::InstanceLogger.new(i_methods: self.instance_methods(false))
61
+ # extend DebugLogging::InstanceLogger
62
+ # i_logged instance_methods(false)
63
63
  #
64
64
  # def will_not_be_logged; false; end
65
65
  #
@@ -68,29 +68,36 @@ require "debug_logging/class_logger"
68
68
  ####################
69
69
 
70
70
  module DebugLogging
71
- def self.extended(base)
72
- base.send(:extend, ArgumentPrinter)
73
- base.send(:extend, ApiClassMethods)
74
- base.send(:extend, ConfigClassMethods)
75
- base.debug_config_reset(Configuration.new(**debug_logging_configuration.to_hash))
76
- base.class_eval do
77
- def base.inherited(subclass)
78
- subclass.debug_config_reset(Configuration.new(**debug_config.to_hash))
71
+ # We can't compare with nil to check for no arguments passed as a configuration value,
72
+ # because nil can be an argument passed, hence:
73
+ ACTUAL_NOTHING = Object.new
74
+
75
+ class << self
76
+ def extended(base)
77
+ base.send(:extend, ArgumentPrinter)
78
+ base.send(:include, ArgumentPrinter)
79
+ base.send(:extend, ApiClassMethods)
80
+ base.send(:extend, ConfigClassMethods)
81
+ base.debug_config_reset(Configuration.new(**debug_logging_configuration.to_hash))
82
+ base.class_eval do
83
+ def base.inherited(subclass)
84
+ subclass.debug_config_reset(Configuration.new(**debug_config.to_hash))
85
+ end
79
86
  end
80
87
  end
81
- end
82
88
 
83
- #### API ####
89
+ #### API ####
84
90
 
85
- # For single statement global config in an initializer
86
- # e.g. DebugLogging.configuration.ellipsis = "..."
87
- def self.configuration
88
- self.debug_logging_configuration ||= Configuration.new
89
- end
91
+ # For single statement global config in an initializer
92
+ # e.g. DebugLogging.configuration.ellipsis = "..."
93
+ def configuration
94
+ self.debug_logging_configuration ||= Configuration.new
95
+ end
90
96
 
91
- # For global config in an initializer with a block
92
- def self.configure
93
- yield(configuration)
97
+ # For global config in an initializer with a block
98
+ def configure
99
+ yield(configuration)
100
+ end
94
101
  end
95
102
 
96
103
  module ApiClassMethods
@@ -226,6 +233,22 @@ module DebugLogging
226
233
  @debug_logging_configuration.colorized_chain_for_class = colorized_chain_for_class
227
234
  end
228
235
 
236
+ def debug_add_timestamp
237
+ @debug_logging_configuration.add_timestamp
238
+ end
239
+
240
+ def debug_add_timestamp=(add_timestamp)
241
+ @debug_logging_configuration.add_timestamp = add_timestamp
242
+ end
243
+
244
+ def debug_time_formatter_proc
245
+ @debug_logging_configuration.time_formatter_proc
246
+ end
247
+
248
+ def debug_time_formatter_proc=(time_formatter_proc)
249
+ @debug_logging_configuration.time_formatter_proc = time_formatter_proc
250
+ end
251
+
229
252
  def debug_add_invocation_id
230
253
  @debug_logging_configuration.add_invocation_id
231
254
  end
@@ -1,5 +1,3 @@
1
- # frozen_string_literal: true
2
-
3
1
  # Simpler version of what the sibling DebugLogging library does. Included as a bauble.
4
2
  #
5
3
  ############# THIS IS A BAUBLE
@@ -57,11 +55,11 @@ class SimpleDebugLogging < Module
57
55
  define_method(method_to_log.to_sym) do |*args|
58
56
  method_return_value = nil
59
57
  invocation_id = " ~#{args.object_id}@#{Time.now.to_i}~" if args
60
- puts "#{self}.#{method_to_log}(#{args.map(&:inspect).join(", ")})#{invocation_id}"
58
+ puts "#{self}::#{method_to_log}(#{args.map(&:inspect).join(", ")})#{invocation_id}"
61
59
  elapsed = Benchmark.realtime do
62
60
  method_return_value = original_method.call(*args)
63
61
  end
64
- puts "#{self}.#{method_to_log} ~#{args.hash}~ complete in #{elapsed}s#{invocation_id}"
62
+ puts "#{self}::#{method_to_log} ~#{args.hash}~ complete in #{elapsed}s#{invocation_id}"
65
63
  method_return_value
66
64
  end
67
65
  end
data.tar.gz.sig CHANGED
Binary file
metadata CHANGED
@@ -1,11 +1,11 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: debug_logging
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.1.9
4
+ version: 4.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Boling
8
- - 'John '
8
+ - John Gillson
9
9
  - guckin
10
10
  autorequire:
11
11
  bindir: exe
@@ -38,7 +38,7 @@ cert_chain:
38
38
  KuxrfYrN+9HvMdm+nZ6TypmKftHY3Gj+/uu+g8Icm/zrvTWAEE0mcJOkfrIoNPJb
39
39
  pF8dMA==
40
40
  -----END CERTIFICATE-----
41
- date: 2023-10-31 00:00:00.000000000 Z
41
+ date: 2024-03-01 00:00:00.000000000 Z
42
42
  dependencies:
43
43
  - !ruby/object:Gem::Dependency
44
44
  name: colorize
@@ -68,20 +68,6 @@ dependencies:
68
68
  - - ">="
69
69
  - !ruby/object:Gem::Version
70
70
  version: 5.2.4.4
71
- - !ruby/object:Gem::Dependency
72
- name: byebug
73
- requirement: !ruby/object:Gem::Requirement
74
- requirements:
75
- - - ">="
76
- - !ruby/object:Gem::Version
77
- version: '11'
78
- type: :development
79
- prerelease: false
80
- version_requirements: !ruby/object:Gem::Requirement
81
- requirements:
82
- - - ">="
83
- - !ruby/object:Gem::Version
84
- version: '11'
85
71
  - !ruby/object:Gem::Dependency
86
72
  name: rake
87
73
  requirement: !ruby/object:Gem::Requirement
@@ -170,20 +156,20 @@ dependencies:
170
156
  requirements:
171
157
  - - "~>"
172
158
  - !ruby/object:Gem::Version
173
- version: '12.1'
159
+ version: '22.1'
174
160
  - - ">="
175
161
  - !ruby/object:Gem::Version
176
- version: 12.1.1
162
+ version: 22.1.3
177
163
  type: :development
178
164
  prerelease: false
179
165
  version_requirements: !ruby/object:Gem::Requirement
180
166
  requirements:
181
167
  - - "~>"
182
168
  - !ruby/object:Gem::Version
183
- version: '12.1'
169
+ version: '22.1'
184
170
  - - ">="
185
171
  - !ruby/object:Gem::Version
186
- version: 12.1.1
172
+ version: 22.1.3
187
173
  - !ruby/object:Gem::Dependency
188
174
  name: rubocop-packaging
189
175
  requirement: !ruby/object:Gem::Requirement
@@ -304,6 +290,8 @@ executables: []
304
290
  extensions: []
305
291
  extra_rdoc_files: []
306
292
  files:
293
+ - CHANGELOG.md
294
+ - CODE_OF_CONDUCT.md
307
295
  - CONTRIBUTING.md
308
296
  - LICENSE.txt
309
297
  - README.md
@@ -331,10 +319,10 @@ licenses:
331
319
  - MIT
332
320
  metadata:
333
321
  homepage_uri: https://github.com/pboling/debug_logging
334
- source_code_uri: https://github.com/pboling/debug_logging/tree/v3.1.9
335
- changelog_uri: https://github.com/pboling/debug_logging/blob/v3.1.9/CHANGELOG.md
322
+ source_code_uri: https://github.com/pboling/debug_logging/tree/v4.0.1
323
+ changelog_uri: https://github.com/pboling/debug_logging/blob/v4.0.1/CHANGELOG.md
336
324
  bug_tracker_uri: https://github.com/pboling/debug_logging/issues
337
- documentation_uri: https://www.rubydoc.info/gems/debug_logging/3.1.9
325
+ documentation_uri: https://www.rubydoc.info/gems/debug_logging/4.0.1
338
326
  wiki_uri: https://github.com/pboling/debug_logging/wiki
339
327
  funding_uri: https://liberapay.com/pboling
340
328
  rubygems_mfa_required: 'true'
@@ -346,17 +334,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
346
334
  requirements:
347
335
  - - ">="
348
336
  - !ruby/object:Gem::Version
349
- version: '2.4'
350
- - - "<"
351
- - !ruby/object:Gem::Version
352
- version: '3'
337
+ version: '3.1'
353
338
  required_rubygems_version: !ruby/object:Gem::Requirement
354
339
  requirements:
355
340
  - - ">="
356
341
  - !ruby/object:Gem::Version
357
342
  version: '0'
358
343
  requirements: []
359
- rubygems_version: 3.1.6
344
+ rubygems_version: 3.5.6
360
345
  signing_key:
361
346
  specification_version: 4
362
347
  summary: Drop-in debug logging useful when a call stack gets unruly
metadata.gz.sig CHANGED
Binary file