debug_logging 4.0.0 → 4.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/CHANGELOG.md +41 -27
- data/README.md +28 -3
- data/SECURITY.md +2 -2
- data/lib/debug_logging/argument_printer.rb +20 -14
- data/lib/debug_logging/configuration.rb +19 -10
- data/lib/debug_logging/constants.rb +11 -7
- data/lib/debug_logging/instance_logger.rb +22 -0
- data/lib/debug_logging/instance_logger_modulizer.rb +8 -4
- data/lib/debug_logging/log_subscriber.rb +2 -2
- data/lib/debug_logging/util.rb +16 -0
- data/lib/debug_logging/version.rb +1 -1
- data/lib/debug_logging.rb +16 -0
- data.tar.gz.sig +0 -0
- metadata +5 -5
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ca22c0dbc789a56d7f02d3ef685d92fb0423592bde3fccaa733afcd577c88a78
|
4
|
+
data.tar.gz: 279bdd5ecde603ff0be14ec128bea893a05a53d0d4c0f42fbdb6663964fff178
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 352720fb350ee3c404f64b631c6f27f178ca8bb07b66e779cb26a66077708df9e716f7b0ef49e80035f44a45bc8081e436f420a14ac07f17d44a6b7e67ba46d1
|
7
|
+
data.tar.gz: 5effc5e2ef194e6e90c9c57f3378523a6fda0d5ab2b4d5fd7c4161bc542385b9796cfef56f015a756a75ead1969bb83f94c81d3dc4ba54607b7d9e2adab4c46f
|
checksums.yaml.gz.sig
CHANGED
Binary file
|
data/CHANGELOG.md
CHANGED
@@ -11,7 +11,17 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
11
11
|
### Fixed
|
12
12
|
### Removed
|
13
13
|
|
14
|
-
## [4.0.0] -
|
14
|
+
## [4.0.1] ([tag][4.0.1t]) - 2024-03-01
|
15
|
+
### Added
|
16
|
+
- Support for all Numeric types to be used as monotonic timestamps for ActiveSupport::Notifications
|
17
|
+
- `time_formatter_proc` - used to format timestamp added to beginning of log lines
|
18
|
+
- `add_timestamp` - Add timestamp to front of each log line
|
19
|
+
### Changed
|
20
|
+
- `DebugLogging::ArgumentPrinter.debug_time_to_s` => `DebugLogging::ArgumentPrinter.debug_event_time_to_s`
|
21
|
+
### Fixed
|
22
|
+
### Removed
|
23
|
+
|
24
|
+
## [4.0.0] ([tag][4.0.0t]) - 2024-02-28
|
15
25
|
### Added
|
16
26
|
- Class method DSL:
|
17
27
|
- `logged`
|
@@ -30,57 +40,57 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
30
40
|
- Support for `include DebugLogging::InstanceLogger.new(...)`
|
31
41
|
- Support for `include DebugLogging::InstanceNotifier.new(...)`
|
32
42
|
|
33
|
-
## [3.1.9] - 2023-10-31
|
43
|
+
## [3.1.9] ([tag][3.1.9t]) - 2023-10-31
|
34
44
|
### Fixed
|
35
45
|
- Maximum Ruby version is 2.7. Versions 3.x are not compatible with Ruby >= 3
|
36
46
|
|
37
|
-
## [3.1.8] - 2020-12-19
|
47
|
+
## [3.1.8] ([tag][3.1.8t]) - 2020-12-19
|
38
48
|
|
39
|
-
## [3.1.7] - 2020-12-19
|
49
|
+
## [3.1.7] ([tag][3.1.7t]) - 2020-12-19
|
40
50
|
|
41
|
-
## [3.1.6] - tagged, but unreleased
|
51
|
+
## [3.1.6] ([tag][3.1.6t]) - tagged, but unreleased
|
42
52
|
|
43
|
-
## [3.1.5] - 2020-12-18
|
53
|
+
## [3.1.5] ([tag][3.1.5t]) - 2020-12-18
|
44
54
|
|
45
|
-
## [3.1.4] - 2020-12-18
|
55
|
+
## [3.1.4] ([tag][3.1.4t]) - 2020-12-18
|
46
56
|
|
47
|
-
## [3.1.3] - 2020-12-18
|
57
|
+
## [3.1.3] ([tag][3.1.3t]) - 2020-12-18
|
48
58
|
|
49
|
-
## [3.1.2] - 2020-12-10
|
59
|
+
## [3.1.2] ([tag][3.1.2t]) - 2020-12-10
|
50
60
|
|
51
|
-
## [3.1.1] - 2020-12-09
|
61
|
+
## [3.1.1] ([tag][3.1.1t]) - 2020-12-09
|
52
62
|
|
53
|
-
## [3.1.0] - 2020-10-24
|
63
|
+
## [3.1.0] ([tag][3.1.0t]) - 2020-10-24
|
54
64
|
|
55
|
-
## [3.0.0] - 2020-10-07
|
65
|
+
## [3.0.0] ([tag][3.0.0t]) - 2020-10-07
|
56
66
|
|
57
|
-
## [2.0.0] - 2020-10-06
|
67
|
+
## [2.0.0] ([tag][2.0.0t]) - 2020-10-06
|
58
68
|
|
59
|
-
## [1.0.17] - 2018-09-10
|
69
|
+
## [1.0.17] ([tag][1.0.17t]) - 2018-09-10
|
60
70
|
|
61
|
-
## [1.0.16] - 2018-01-16
|
71
|
+
## [1.0.16] ([tag][1.0.16t]) - 2018-01-16
|
62
72
|
|
63
|
-
## [1.0.15] - 2017-10-17
|
73
|
+
## [1.0.15] ([tag][1.0.15t]) - 2017-10-17
|
64
74
|
|
65
|
-
## [1.0.14] - 2017-10-09
|
75
|
+
## [1.0.14] ([tag][1.0.14t]) - 2017-10-09
|
66
76
|
|
67
|
-
## [1.0.13] - 2017-10-08
|
77
|
+
## [1.0.13] ([tag][1.0.13t]) - 2017-10-08
|
68
78
|
|
69
|
-
## [1.0.12] - 2017-10-08
|
79
|
+
## [1.0.12] ([tag][1.0.12t]) - 2017-10-08
|
70
80
|
|
71
|
-
## [1.0.11] - 2017-10-06
|
81
|
+
## [1.0.11] ([tag][1.0.11t]) - 2017-10-06
|
72
82
|
|
73
|
-
## [1.0.10] - 2017-09-26
|
83
|
+
## [1.0.10] ([tag][1.0.10t]) - 2017-09-26
|
74
84
|
|
75
|
-
## [1.0.9] - 2017-09-06
|
85
|
+
## [1.0.9] ([tag][1.0.9t]) - 2017-09-06
|
76
86
|
|
77
|
-
## [1.0.8] - 2017-09-06
|
87
|
+
## [1.0.8] ([tag][1.0.8t]) - 2017-09-06
|
78
88
|
|
79
|
-
## [1.0.7] - 2017-09-06
|
89
|
+
## [1.0.7] ([tag][1.0.7t]) - 2017-09-06
|
80
90
|
|
81
|
-
## [1.0.6] - 2017-09-05
|
91
|
+
## [1.0.6] ([tag][1.0.6t]) - 2017-09-05
|
82
92
|
|
83
|
-
## [1.0.5] ([tag][1.0.
|
93
|
+
## [1.0.5] ([tag][1.0.5t]) - 2017-03-31
|
84
94
|
|
85
95
|
## [1.0.4] ([tag][1.0.4t]) - 2017-03-31
|
86
96
|
|
@@ -95,7 +105,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|
95
105
|
## [0.1.0] ([tag][0.1.0t]) - 2017-03-25
|
96
106
|
- Initial release
|
97
107
|
|
98
|
-
[Unreleased]: https://gitlab.com/kettle-rb/kettle-soup-cover/-/compare/
|
108
|
+
[Unreleased]: https://gitlab.com/kettle-rb/kettle-soup-cover/-/compare/v4.0.1...HEAD
|
109
|
+
[4.0.1t]: https://gitlab.com/pboling/debug_logging/-/tags/v4.0.1
|
110
|
+
[4.0.1]: https://gitlab.com/kettle-rb/kettle-soup-cover/-/compare/v4.0.0...v4.0.1
|
111
|
+
[4.0.0t]: https://gitlab.com/pboling/debug_logging/-/tags/v4.0.0
|
112
|
+
[4.0.0]: https://gitlab.com/kettle-rb/kettle-soup-cover/-/compare/v3.1.9...v4.0.0
|
99
113
|
[3.1.9t]: https://gitlab.com/pboling/debug_logging/-/tags/v3.1.9
|
100
114
|
[3.1.9]: https://gitlab.com/kettle-rb/kettle-soup-cover/-/compare/v3.1.8...v3.1.9
|
101
115
|
[3.1.8t]: https://gitlab.com/pboling/debug_logging/-/tags/v3.1.8
|
data/README.md
CHANGED
@@ -148,7 +148,7 @@ Recommend creating `config/initializers/debug_logging.rb`, or adding to `config/
|
|
148
148
|
```ruby
|
149
149
|
# Showing the defaults
|
150
150
|
DebugLogging.configuration.logger = Logger.new($stdout) # you probably want to override to be the Rails.logger, and if so you can't set it in the initializer, as it needs to be set after Rails.logger is set.
|
151
|
-
DebugLogging.configuration.log_level = :debug # at what level
|
151
|
+
DebugLogging.configuration.log_level = :debug # at what level are the messages created by this gem sent at?
|
152
152
|
DebugLogging.configuration.multiple_last_hashes = false # pass every hash argument to last_hash_to_s_proc?
|
153
153
|
DebugLogging.configuration.last_hash_to_s_proc = nil # e.g. ->(hash) { "keys: #{hash.keys}" }
|
154
154
|
DebugLogging.configuration.last_hash_max_length = 1_000
|
@@ -160,6 +160,8 @@ DebugLogging.configuration.active_support_notifications = false
|
|
160
160
|
DebugLogging.configuration.colorized_chain_for_method = false # e.g. ->(colorized_string) { colorized_string.red.on_blue.underline }
|
161
161
|
DebugLogging.configuration.colorized_chain_for_class = false # e.g. ->(colorized_string) { colorized_string.colorize(:light_blue ).colorize( :background => :red) }
|
162
162
|
DebugLogging.configuration.add_invocation_id = true # identify a method call uniquely in a log, pass a proc for colorization, e.g. ->(colorized_string) { colorized_string.light_black }
|
163
|
+
DebugLogging.configuration.time_formatter_proc = DebugLogging::Constants::DEFAULT_TIME_FORMATTER
|
164
|
+
DebugLogging.configuration.add_timestamp = false
|
163
165
|
DebugLogging.configuration.ellipsis = " ✂️ …".freeze
|
164
166
|
DebugLogging.configuration.mark_scope_exit = true # Only has an effect if benchmarking is off, since benchmarking always marks the scope exit
|
165
167
|
DebugLogging.configuration.add_payload = false # or a proc which will be called to print the payload
|
@@ -183,6 +185,8 @@ DebugLogging.configure do |config|
|
|
183
185
|
config.active_support_notifications = false
|
184
186
|
config.colorized_chain_for_method = false # e.g. ->(colorized_string) { colorized_string.red.on_blue.underline }
|
185
187
|
config.colorized_chain_for_class = false # e.g. ->(colorized_string) { colorized_string.colorize(:light_blue ).colorize( :background => :red) }
|
188
|
+
config.time_formatter_proc = DebugLogging::Constants::DEFAULT_TIME_FORMATTER
|
189
|
+
config.add_timestamp = false
|
186
190
|
config.add_invocation_id = true # identify a method call uniquely in a log, pass a proc for colorization, e.g. ->(colorized_string) { colorized_string.light_black }
|
187
191
|
config.ellipsis = " ✂️ …".freeze
|
188
192
|
config.mark_scope_exit = true # Only has an effect if benchmarking is off, since benchmarking always marks the scope exit
|
@@ -208,7 +212,7 @@ Just send along a hash of the config options, similar to the following:
|
|
208
212
|
|
209
213
|
See the example class below, and the specs.
|
210
214
|
|
211
|
-
**NOTE ON** `Rails.logger` - It will probably be nil in your initializer, so setting the `config.logger` to `Rails.logger` there will result in setting it to `nil`, which means the default will end up being used: `Logger.new(
|
215
|
+
**NOTE ON** `Rails.logger` - It will probably be nil in your initializer, so setting the `config.logger` to `Rails.logger` there will result in setting it to `nil`, which means the default will end up being used: `Logger.new($stdout)`. Instead just config the logger in your application.rb, or anytime later, but *before your classes get loaded* and start inheriting the config:
|
212
216
|
|
213
217
|
```ruby
|
214
218
|
DebugLogging.configuration.logger = Rails.logger
|
@@ -294,7 +298,28 @@ class Car
|
|
294
298
|
# Override configuration options for any instance method(s), by passing a hash as the last argument
|
295
299
|
# In the last hash any non-Configuration keys will be data that gets logged,
|
296
300
|
# and also made available to last_hash_to_s_proc
|
297
|
-
|
301
|
+
# Here's an example that sets every possible option, while also showing what the default values are!
|
302
|
+
i_logged [:faster], {
|
303
|
+
logger: Logger.new($stdout), # probably want to override to be the Rails.logger
|
304
|
+
log_level: :debug, # at what level do the messages created by this gem sent at?
|
305
|
+
multiple_last_hashes: false,
|
306
|
+
last_hash_to_s_proc: nil, # e.g. ->(hash) { "keys: #{hash.keys}" }
|
307
|
+
last_hash_max_length: 1_000,
|
308
|
+
args_to_s_proc: nil, # e.g. ->(*record) { "record id: #{record.first.id}" }
|
309
|
+
args_max_length: 1_000,
|
310
|
+
colorized_chain_for_method: false, # e.g. ->(colorized_string) { colorized_string.red.on_blue.underline }
|
311
|
+
colorized_chain_for_class: false, # e.g. ->(colorized_string) { colorized_string.colorize(:light_blue ).colorize( :background => :red) }
|
312
|
+
add_invocation_id: true, # allows unique identification of method call; association of entry and exit log lines
|
313
|
+
ellipsis: " ✂️ …".freeze,
|
314
|
+
mark_scope_exit: false,
|
315
|
+
add_payload: true, # Can also be a proc returning a string, which will be called when printing the payload
|
316
|
+
payload_max_length: 1_000,
|
317
|
+
error_handler_proc: nil,
|
318
|
+
time_formatter_proc: DebugLogging::Constants::DEFAULT_TIME_FORMATTER,
|
319
|
+
add_timestamp: false,
|
320
|
+
instance_benchmarks: false,
|
321
|
+
class_benchmarks: false,
|
322
|
+
}
|
298
323
|
|
299
324
|
# You can also use `i_logged` as a true method decorator:
|
300
325
|
i_logged def slower
|
data/SECURITY.md
CHANGED
@@ -7,11 +7,13 @@ module DebugLogging
|
|
7
7
|
"completed in #{format("%f", tms.real)}s (#{format("%f", tms.total)}s CPU)"
|
8
8
|
end
|
9
9
|
|
10
|
-
def debug_invocation_id_to_s(args: nil, kwargs: nil, config_proxy: nil)
|
10
|
+
def debug_invocation_id_to_s(args: nil, kwargs: nil, start_at: nil, config_proxy: nil)
|
11
11
|
return "" unless (args || kwargs) && config_proxy
|
12
12
|
|
13
13
|
if config_proxy.debug_add_invocation_id
|
14
|
-
|
14
|
+
time = start_at ? Util.debug_time(start_at) : Time.now
|
15
|
+
unique_id = (time.to_f.to_s % "%#-21a")[4..-4]
|
16
|
+
invocation = " ~#{args.object_id}|#{kwargs.object_id}@#{unique_id}~"
|
15
17
|
case config_proxy.debug_add_invocation_id
|
16
18
|
when true
|
17
19
|
invocation
|
@@ -23,21 +25,25 @@ module DebugLogging
|
|
23
25
|
end
|
24
26
|
end
|
25
27
|
|
26
|
-
|
28
|
+
# @return [String]
|
29
|
+
def debug_time_to_s(time_or_monotonic, config_proxy: nil)
|
30
|
+
return "" unless config_proxy&.debug_add_timestamp
|
31
|
+
return config_proxy.debug_time_formatter_proc.call(Time.now) unless time_or_monotonic
|
32
|
+
|
33
|
+
time = Util.debug_time(time_or_monotonic)
|
34
|
+
|
35
|
+
config_proxy.debug_time_formatter_proc.call(time)
|
36
|
+
end
|
37
|
+
|
38
|
+
# A custom time format will never apply here, because ActiveSupport::Notifications have a required time format
|
39
|
+
def debug_event_time_to_s(time_or_monotonic)
|
27
40
|
# Time format must match:
|
28
41
|
# \d{4,}-\d{2}-\d{2} \d{2}:\d{2}:\d{2} [-+]\d{4}
|
29
42
|
# YYYY-MM-DD HH:mm:ss +00:00
|
30
43
|
# strftime("%F %T %z")
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
when Time, DateTime
|
35
|
-
time_or_monotonic.strftime("%F %T %z")
|
36
|
-
when String
|
37
|
-
Time.parse(time_or_monotonic).strftime("%F %T %z")
|
38
|
-
else
|
39
|
-
time_or_monotonic
|
40
|
-
end
|
44
|
+
time_or_monotonic = Time.now if time_or_monotonic.nil? || (time_or_monotonic.respond_to?(:empty?) && time_or_monotonic.empty?)
|
45
|
+
time = Util.debug_time(time_or_monotonic)
|
46
|
+
DebugLogging::Constants::EVENT_TIME_FORMATTER.call(time)
|
41
47
|
end
|
42
48
|
|
43
49
|
def debug_invocation_to_s(klass: nil, separator: nil, method_to_log: nil, config_proxy: nil)
|
@@ -188,7 +194,7 @@ module DebugLogging
|
|
188
194
|
proc_name: "add_payload",
|
189
195
|
proc: config_proxy.debug_add_payload,
|
190
196
|
args: payload,
|
191
|
-
max_length: config_proxy.
|
197
|
+
max_length: config_proxy.debug_payload_max_length,
|
192
198
|
)
|
193
199
|
printed_payload += printed
|
194
200
|
printed_payload += config_proxy.debug_ellipsis if add_payload_ellipsis
|
@@ -12,16 +12,25 @@ module DebugLogging
|
|
12
12
|
# extend DebugLogging::InstanceLogger
|
13
13
|
# i_logged [:drive, :stop],
|
14
14
|
# {
|
15
|
-
# logger: Logger.new(
|
16
|
-
# log_level: :debug # at what level do the messages created by this gem sent at?
|
17
|
-
#
|
18
|
-
#
|
19
|
-
#
|
20
|
-
#
|
21
|
-
#
|
22
|
-
#
|
23
|
-
#
|
24
|
-
#
|
15
|
+
# logger: Logger.new($stdout), # probably want to override to be the Rails.logger
|
16
|
+
# log_level: :debug, # at what level do the messages created by this gem sent at?
|
17
|
+
# multiple_last_hashes: false,
|
18
|
+
# last_hash_to_s_proc: nil, # e.g. ->(hash) { "keys: #{hash.keys}" }
|
19
|
+
# last_hash_max_length: 1_000,
|
20
|
+
# args_to_s_proc: nil, # e.g. ->(*record) { "record id: #{record.first.id}" }
|
21
|
+
# args_max_length: 1_000,
|
22
|
+
# colorized_chain_for_method: false, # e.g. ->(colorized_string) { colorized_string.red.on_blue.underline }
|
23
|
+
# colorized_chain_for_class: false, # e.g. ->(colorized_string) { colorized_string.colorize(:light_blue ).colorize( :background => :red) }
|
24
|
+
# add_invocation_id: true, # allows unique identification of method call; association of entry and exit log lines
|
25
|
+
# ellipsis: " ✂️ …".freeze,
|
26
|
+
# mark_scope_exit: false,
|
27
|
+
# add_payload: true, # Can also be a proc returning a string, which will be called when printing the payload
|
28
|
+
# payload_max_length: 1_000,
|
29
|
+
# error_handler_proc: nil,
|
30
|
+
# time_formatter_proc: DebugLogging::Constants::DEFAULT_TIME_FORMATTER,
|
31
|
+
# add_timestamp: false,
|
32
|
+
# instance_benchmarks: false,
|
33
|
+
# class_benchmarks: false,
|
25
34
|
# }
|
26
35
|
#
|
27
36
|
CONFIG_KEYS.each do |key|
|
@@ -1,23 +1,27 @@
|
|
1
1
|
module DebugLogging
|
2
2
|
module Constants
|
3
3
|
DEFAULT_ELLIPSIS = " ✂️ …"
|
4
|
+
DEFAULT_TIME_FORMATTER = ->(time) { "[#{time.strftime("%Y%m%d %H:%M:%S")}] " }
|
5
|
+
EVENT_TIME_FORMATTER = ->(time) { time.strftime("%F %T %z") }
|
4
6
|
CONFIG_ATTRS_DEFAULTS = {
|
5
7
|
enabled: true,
|
6
|
-
logger: Logger.new($stdout),
|
7
|
-
log_level: :debug,
|
8
|
+
logger: Logger.new($stdout), # probably want to override to be the Rails.logger
|
9
|
+
log_level: :debug, # at what level do the messages created by this gem sent at?
|
8
10
|
multiple_last_hashes: false,
|
9
|
-
last_hash_to_s_proc: nil,
|
11
|
+
last_hash_to_s_proc: nil, # e.g. ->(hash) { "keys: #{hash.keys}" }
|
10
12
|
last_hash_max_length: 1_000,
|
11
|
-
args_to_s_proc: nil,
|
13
|
+
args_to_s_proc: nil, # e.g. ->(*record) { "record id: #{record.first.id}" }
|
12
14
|
args_max_length: 1_000,
|
13
|
-
colorized_chain_for_method: false,
|
14
|
-
colorized_chain_for_class: false,
|
15
|
-
add_invocation_id: true,
|
15
|
+
colorized_chain_for_method: false, # e.g. ->(colorized_string) { colorized_string.red.on_blue.underline }
|
16
|
+
colorized_chain_for_class: false, # e.g. ->(colorized_string) { colorized_string.colorize(:light_blue ).colorize( :background => :red) }
|
17
|
+
add_invocation_id: true, # allows unique identification of method call; association of entry and exit log lines
|
16
18
|
ellipsis: DEFAULT_ELLIPSIS,
|
17
19
|
mark_scope_exit: false,
|
18
20
|
add_payload: true, # Can also be a proc returning a string, which will be called when printing the payload
|
19
21
|
payload_max_length: 1_000,
|
20
22
|
error_handler_proc: nil,
|
23
|
+
time_formatter_proc: DEFAULT_TIME_FORMATTER,
|
24
|
+
add_timestamp: false,
|
21
25
|
}.freeze
|
22
26
|
CONFIG_ATTRS = CONFIG_ATTRS_DEFAULTS.keys
|
23
27
|
CONFIG_READERS_DEFAULTS = {
|
@@ -1,5 +1,27 @@
|
|
1
1
|
module DebugLogging
|
2
2
|
module InstanceLogger
|
3
|
+
# NOTE: These params can be passed in / hidden in a last hash of *args
|
4
|
+
# NOTE: They can also be passed in discretely for each method, by passing *args as an array of arrays
|
5
|
+
# TODO: Refactor to use modern Ruby 3 *args, **kwargs instead
|
6
|
+
# @param logger [Logger] Logger.new($stdout), # probably want to override to be the Rails.logger
|
7
|
+
# @param log_level [Symbol] default: :debug, at what level do the messages created by this gem sent at?
|
8
|
+
# @param multiple_last_hashes [true, false] default: false,
|
9
|
+
# @param last_hash_to_s_proc [nil, Proc] default: nil, e.g. ->(hash) { "keys: #{hash.keys}" }
|
10
|
+
# @param last_hash_max_length [Integer] default: 1_000,
|
11
|
+
# @param args_to_s_proc [nil, Proc] default: nil, e.g. ->(*record) { "record id: #{record.first.id}" }
|
12
|
+
# @param args_max_length [Integer] default: 1_000,
|
13
|
+
# @param colorized_chain_for_method [false, Proc] default: false, e.g. ->(colorized_string) { colorized_string.red.on_blue.underline }
|
14
|
+
# @param colorized_chain_for_class [false, Proc] default: false, e.g. ->(colorized_string) { colorized_string.colorize(:light_blue ).colorize( :background => :red) }
|
15
|
+
# @param add_invocation_id [true, false] default: true, allows unique identification of method call; association of entry and exit log lines
|
16
|
+
# @param ellipsis [String] default: " ✂️ …".freeze,
|
17
|
+
# @param mark_scope_exit [true, false] default: false,
|
18
|
+
# @param add_payload [true, false, Proc] default: true, # Can also be a proc returning a string, which will be called when printing the payload
|
19
|
+
# @param payload_max_length [Integer] default: 1_000,
|
20
|
+
# @param error_handler_proc [nil, Proc] default: nil,
|
21
|
+
# @param time_formatter_proc [nil, Proc] default: DebugLogging::Constants::DEFAULT_TIME_FORMATTER,
|
22
|
+
# @param add_timestamp [true, false] default: false,
|
23
|
+
# @param instance_benchmarks [true, false] default: false,
|
24
|
+
# @param class_benchmarks [true, false] default: false,
|
3
25
|
def i_logged(*methods_to_log)
|
4
26
|
methods_to_log, payload, config_opts = DebugLogging::Util.extract_payload_and_config(
|
5
27
|
method_names: methods_to_log,
|
@@ -28,19 +28,22 @@ module DebugLogging
|
|
28
28
|
method_to_log: method_to_log,
|
29
29
|
config_proxy: config_proxy,
|
30
30
|
)
|
31
|
-
|
31
|
+
start_at = Time.now
|
32
|
+
start_timestamp = self.class.debug_time_to_s(start_at, config_proxy:)
|
33
|
+
invocation_id = self.class.debug_invocation_id_to_s(args:, kwargs:, start_at:, config_proxy:)
|
32
34
|
config_proxy.log do
|
33
35
|
paydirt = DebugLogging::Util.payload_instance_variable_hydration(scope: self, payload: method_payload)
|
34
36
|
signature = self.class.debug_signature_to_s(args:, kwargs:, config_proxy:)
|
35
37
|
paymud = debug_payload_to_s(payload: paydirt, config_proxy:)
|
36
|
-
"#{log_prefix}#{signature}#{invocation_id} debug: #{paymud}"
|
38
|
+
"#{start_timestamp}#{log_prefix}#{signature}#{invocation_id} debug: #{paymud}"
|
37
39
|
end
|
38
40
|
if config_proxy.benchmarkable_for?(:debug_instance_benchmarks)
|
39
41
|
tms = Benchmark.measure do
|
40
42
|
method_return_value = super(*args, **kwargs, &block)
|
41
43
|
end
|
44
|
+
end_timestamp = self.class.debug_time_to_s(Time.now, config_proxy:)
|
42
45
|
config_proxy.log do
|
43
|
-
"#{log_prefix} #{self.class.debug_benchmark_to_s(tms: tms)}#{invocation_id}"
|
46
|
+
"#{end_timestamp}#{log_prefix} #{self.class.debug_benchmark_to_s(tms: tms)}#{invocation_id}"
|
44
47
|
end
|
45
48
|
else
|
46
49
|
begin
|
@@ -53,8 +56,9 @@ module DebugLogging
|
|
53
56
|
end
|
54
57
|
end
|
55
58
|
if config_proxy.exit_scope_markable? && invocation_id && !invocation_id.empty?
|
59
|
+
end_timestamp = self.class.debug_time_to_s(Time.now, config_proxy:)
|
56
60
|
config_proxy.log do
|
57
|
-
"#{log_prefix} completed#{invocation_id}"
|
61
|
+
"#{end_timestamp}#{log_prefix} completed#{invocation_id}"
|
58
62
|
end
|
59
63
|
end
|
60
64
|
end
|
@@ -32,8 +32,8 @@ module DebugLogging
|
|
32
32
|
{
|
33
33
|
name: event.name,
|
34
34
|
duration: Rational(event.duration, 1000).to_f,
|
35
|
-
time:
|
36
|
-
end:
|
35
|
+
time: debug_event_time_to_s(event.time),
|
36
|
+
end: debug_event_time_to_s(event.end),
|
37
37
|
args: debug_signature_to_s(args: args, config_proxy: config_proxy),
|
38
38
|
payload: debug_payload_to_s(payload: payload, config_proxy: config_proxy),
|
39
39
|
}
|
data/lib/debug_logging/util.rb
CHANGED
@@ -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)
|
@@ -36,6 +50,8 @@ module DebugLogging
|
|
36
50
|
# logged :meth1, :meth2, :meth3 without options is valid
|
37
51
|
method_names
|
38
52
|
end
|
53
|
+
else
|
54
|
+
raise ArgumentError, "unknown type for method_names: #{method_names.class}"
|
39
55
|
end
|
40
56
|
[method_names, payload, config_opts]
|
41
57
|
end
|
data/lib/debug_logging.rb
CHANGED
@@ -233,6 +233,22 @@ module DebugLogging
|
|
233
233
|
@debug_logging_configuration.colorized_chain_for_class = colorized_chain_for_class
|
234
234
|
end
|
235
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
|
+
|
236
252
|
def debug_add_invocation_id
|
237
253
|
@debug_logging_configuration.add_invocation_id
|
238
254
|
end
|
data.tar.gz.sig
CHANGED
Binary file
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: debug_logging
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.0.
|
4
|
+
version: 4.0.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Peter Boling
|
@@ -38,7 +38,7 @@ cert_chain:
|
|
38
38
|
KuxrfYrN+9HvMdm+nZ6TypmKftHY3Gj+/uu+g8Icm/zrvTWAEE0mcJOkfrIoNPJb
|
39
39
|
pF8dMA==
|
40
40
|
-----END CERTIFICATE-----
|
41
|
-
date: 2024-
|
41
|
+
date: 2024-03-01 00:00:00.000000000 Z
|
42
42
|
dependencies:
|
43
43
|
- !ruby/object:Gem::Dependency
|
44
44
|
name: colorize
|
@@ -319,10 +319,10 @@ licenses:
|
|
319
319
|
- MIT
|
320
320
|
metadata:
|
321
321
|
homepage_uri: https://github.com/pboling/debug_logging
|
322
|
-
source_code_uri: https://github.com/pboling/debug_logging/tree/v4.0.
|
323
|
-
changelog_uri: https://github.com/pboling/debug_logging/blob/v4.0.
|
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
|
324
324
|
bug_tracker_uri: https://github.com/pboling/debug_logging/issues
|
325
|
-
documentation_uri: https://www.rubydoc.info/gems/debug_logging/4.0.
|
325
|
+
documentation_uri: https://www.rubydoc.info/gems/debug_logging/4.0.1
|
326
326
|
wiki_uri: https://github.com/pboling/debug_logging/wiki
|
327
327
|
funding_uri: https://liberapay.com/pboling
|
328
328
|
rubygems_mfa_required: 'true'
|
metadata.gz.sig
CHANGED
Binary file
|