ruby_smart-simple_logger 1.3.0 → 1.4.0

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,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 101c7a9ab2862c9ff3e7ace74f812a20a522dfa7fa8c6fcdf9f9accc53fd29e2
4
- data.tar.gz: 1e1f7d6e1c9cbfe48a21cc8cceaa7cd37de7712363ae78e80bcff87aa6c5ca5a
3
+ metadata.gz: 499ca8f400db9b2df6a9e3017fece6c7e2b94c32c72feb2d04c3a7013a946c4e
4
+ data.tar.gz: f684b602ec79afe45e2cebf5b158eacfab127cd1af7e9aee994a7ec824b0f802
5
5
  SHA512:
6
- metadata.gz: 875fc9ea64929088e6a445f43b1e3a0c7b1c92de106a53c8112c68a3eb28ab5ea081c2a1e21d7d672d7e3109c68e68a83283be41364d65b2c450b6932408e15a
7
- data.tar.gz: 9be8b0019a5afb3b3a9050dcb6139d9cf2ffe9fbd89549ebb717e8e4a2b59ee981dad95948400836a78e8b8205a324dbd2a35dea6638567143e37cbc93425e32
6
+ metadata.gz: aa7911b6005d56ffc56585674bd90ff47f07bb0e632b08447c52e4f4222996ca52d783ab44fcae057b034b2920f0b7e0e5cb044be66a7c79be4dcb1ff18abcc6
7
+ data.tar.gz: 9f1ae4aed0ca7965cbe57d24223a7283915cf7ab876a467945da7269ea6bb66f292704f7e48400a260542eb5b35dc0898b277c5ad338443e459a529e9f5bebf5
data/README.md CHANGED
@@ -9,7 +9,7 @@
9
9
  [![Coverage Status](https://coveralls.io/repos/github/ruby-smart/simple_logger/badge.svg?branch=main&kill_cache=1)](https://coveralls.io/github/ruby-smart/simple_logger?branch=main)
10
10
  [![Tests](https://github.com/ruby-smart/simple_logger/actions/workflows/ruby.yml/badge.svg)](https://github.com/ruby-smart/simple_logger/actions/workflows/ruby.yml)
11
11
 
12
- A simple, multifunctional logging library for Ruby.
12
+ A simple, multifunctional logging library for Ruby (and Rails).
13
13
  It features a fast, customizable logging with multi-device support (e.g. log to STDOUT AND file).
14
14
  Special (PRE-defined) scenes can be used for interactive CLI and better logging visibility.
15
15
 
@@ -36,7 +36,7 @@ Or install it yourself as:
36
36
  ## Enhancements
37
37
  * PRE-defined scenes to fastly create a simple, structured CLI output. _(see [Scenes](#scenes))_
38
38
  * Better log-visibility with masked output through scenes
39
- * ```awesome_print``` gem compatibility for a prettified object debug
39
+ * `awesome_print` gem compatibility for a prettified object debug
40
40
  * Multi-device support (write to logfile & to STDOUT & to ... & to ...)
41
41
  * 'klass_logger' instances for easier access _(see [klass_logger](#klass_logger_Usage))_
42
42
 
@@ -198,10 +198,11 @@ While you can just build a new logger _(or use the klass_logger)_ without any ar
198
198
 
199
199
  ### nil Builtin
200
200
 
201
- A ```nil``` builtin will auto-detect the best logging solution for you.
202
- For CLI or windowed programs it'll just send the logs to ```STDOUT```.
203
- For rails-applications it'll send to the current ```Rails.logger``` instance.
204
- Otherwise it'll store logs temporary in memory _(accessible through the #logs method)_
201
+ A `nil` builtin will auto-detect the best logging solution for you:
202
+ * For CLI or windowed programs it'll just send the logs to `STDOUT`.
203
+ * For Debugging _(e.g. IDE-related debugging gems)_ it'll send the logs to the `Debugger`.
204
+ * For rails-applications it'll send to the current `Rails.logger` instance.
205
+ * Otherwise it'll store logs temporary in memory _(accessible through the #logs method)_
205
206
 
206
207
  **Example:**
207
208
  ```ruby
@@ -211,7 +212,7 @@ logger.debug "some debug"
211
212
 
212
213
  ### stdout / stderr Builtin
213
214
 
214
- A ```:stdout / :stderr``` builtin will send to ```STDOUT / STDERR``` and uses a colored output by default.
215
+ A `:stdout / :stderr` builtin will send to `STDOUT / STDERR` and uses a colored output by default.
215
216
 
216
217
  **Example:**
217
218
  ```ruby
@@ -224,9 +225,34 @@ logger = ::SimpleLogger.new(:stdout)
224
225
  logger.debug "some debug"
225
226
  ```
226
227
 
228
+ ### debugger Builtin
229
+
230
+ A `:debugger` builtin will send to the `Debugger` (e.g. your IDE's debugging gem)
231
+
232
+ **Example:**
233
+ ```ruby
234
+ logger = ::SimpleLogger.new(:debugger)
235
+
236
+ # > will be shown within your debugging gem
237
+ logger.debug "some debug"
238
+ ```
239
+
240
+
241
+ ### null Builtin
242
+
243
+ A `:null` builtin will silently swallow all logging data (so it will not be send).
244
+
245
+ **Example:**
246
+ ```ruby
247
+ logger = ::SimpleLogger.new(:null)
248
+
249
+ # >
250
+ logger.debug "some debug"
251
+ ```
252
+
227
253
  ### rails Builtin
228
254
 
229
- A ```:rails``` builtin will always send to the ```Rails.logger``` instance.
255
+ A `:rails` builtin will always send to the `Rails.logger` instance.
230
256
 
231
257
  **Example:**
232
258
  ```ruby
@@ -238,9 +264,9 @@ logger.debug "some debug"
238
264
 
239
265
  ### proc Builtin
240
266
 
241
- A ```:proc``` builtin will call the provided proc _(through ```options[:proc]```)_ everytime a log will be written.
267
+ A `:proc` builtin will call the provided proc _(through `options[:proc]```)_ everytime a log will be written.
242
268
 
243
- The data will be provided as array _( ```[severity, time, progname, data]``` )_.
269
+ The data will be provided as array _( `[severity, time, progname, data]` )_.
244
270
 
245
271
  **Example:**
246
272
  ```ruby
@@ -255,7 +281,7 @@ logger.debug "some debug"
255
281
 
256
282
  ### memory Builtin
257
283
 
258
- A ```:memory``` builtin will always store the logged data within an _instance variable_ and can be accessed through the ```#logs``` or ```#logs_to_h``` methods.
284
+ A `:memory` builtin will always store the logged data within an _instance variable_ and can be accessed through the `#logs` or `#logs_to_h` methods.
259
285
 
260
286
  **Example:**
261
287
  ```ruby
@@ -276,7 +302,7 @@ logger.logs
276
302
 
277
303
  ### String Builtin
278
304
 
279
- Providing a ```String``` will always create and write to a new logfile.
305
+ Providing a `String` will always create and write to a new logfile.
280
306
 
281
307
  **Example:**
282
308
  ```ruby
@@ -313,7 +339,7 @@ noformat_logger.debug "some debug without color and mask - uses the default form
313
339
 
314
340
  ### Module Builtin
315
341
 
316
- Providing a ```module``` will also create and write to a new logfile.
342
+ Providing a `module` will also create and write to a new logfile.
317
343
  The path depends on the provided module name.
318
344
 
319
345
  **Example:**
@@ -331,13 +357,13 @@ logger.debug "some debug"
331
357
 
332
358
  ### other Builtin
333
359
 
334
- Providing any other Object must respond to ```#write```.
360
+ Providing any other Object must respond to `#write```.
335
361
 
336
362
  -----
337
363
 
338
364
  ## Formats
339
365
 
340
- The default formatter _(if no other was provided through ```opts[:formatter```)_ will provide the following PRE-defined formats:
366
+ The default formatter _(if no other was provided through `opts[:formatter```)_ will provide the following PRE-defined formats:
341
367
  _Also prints a colored output by default._
342
368
 
343
369
  ### default Format
@@ -447,7 +473,7 @@ logger = ::SimpleLogger.new(:stdout, payload: false)
447
473
  ### format
448
474
 
449
475
  Provide a other format.
450
- Possible values: ```:default, :passthrough, :plain, :memory, :datalog```
476
+ Possible values: `:default, :passthrough, :plain, :memory, :datalog```
451
477
  ```ruby
452
478
  logger = ::SimpleLogger.new(format: :default)
453
479
  logger = ::SimpleLogger.new(:memory, format: :passthrough)
@@ -465,7 +491,7 @@ logger.debug "debug 2"
465
491
 
466
492
  ### proc _(:proc-builtin ONLY)_
467
493
 
468
- Provide a callback for the ```:proc``` builtin.
494
+ Provide a callback for the `:proc` builtin.
469
495
  ```ruby
470
496
  logger = ::SimpleLogger.new(:proc, proc: lambda{|data| ... })
471
497
  ```
@@ -528,7 +554,7 @@ logger.debug({a: {custom: 'object'}})
528
554
 
529
555
  ### inspector
530
556
 
531
- Provide a other ```inspector``` method for the data-debug.
557
+ Provide a other `inspector` method for the data-debug.
532
558
 
533
559
  ```ruby
534
560
  logger = ::SimpleLogger.new(inspector: :to_s)
@@ -541,13 +567,13 @@ logger.debug({ a: 1, b: 2 })
541
567
 
542
568
  ## _defaults_
543
569
 
544
- Device default options are still available: ```shift_age, shift_size, progname, datetime_format, shift_period_suffix, binmode```
570
+ Device default options are still available: `shift_age, shift_size, progname, datetime_format, shift_period_suffix, binmode```
545
571
 
546
572
  -----
547
573
 
548
574
  ## Scenes
549
575
 
550
- The following PRE-defined scenes are available. _(You can define your own scenes by using the class method ```.scene```)_
576
+ The following PRE-defined scenes are available. _(You can define your own scenes by using the class method `.scene```)_
551
577
 
552
578
  ### debug(data, subject = 'Debug')
553
579
  ```ruby
@@ -768,6 +794,7 @@ end
768
794
  - line
769
795
  - print
770
796
  - nl
797
+ - model _(rails only)_
771
798
 
772
799
  -----
773
800
 
@@ -784,7 +811,7 @@ This project is intended to be a safe, welcoming space for collaboration, and co
784
811
 
785
812
  The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
786
813
 
787
- A copy of the [LICENSE](docs/LICENSE.txt) can be found @ the docs.
814
+ A copy of the [LICENSE](LICENSE.txt) can be found @ the docs.
788
815
 
789
816
  ## Code of Conduct
790
817
 
data/docs/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # RubySmart::SimpleLogger - CHANGELOG
2
2
 
3
+ ## [1.4.0] - 2024-07-31
4
+ * **[add]** 'null'-device / builtin
5
+ * **[add]** 'debugger'-builtin to send logs to the debugging gem
6
+ * **[add]** new logging method `model` _(for rails applications only)_
7
+ * **[ref]** `nil`-builtin to detect `Debugger` after checking for stdout
8
+ * **[ref]** `mask`-length to 120 _(was 100 by default)_
9
+ * **[ref]** `ruby_smart-support`-gem dependency to 1.5
10
+ * **[fix]** exception _(to build a new device)_ if a Logger was provided
11
+ * **[fix]** mask-reference manipulation on inherited classes
12
+
3
13
  ## [1.3.0] - 2023-08-15
4
14
  * **[add]** exception message within `processed`-scene
5
15
  * **[add]** new logging option `tag`, to prefix a log-string with a [TAG]
@@ -4,7 +4,6 @@ module RubySmart
4
4
  module SimpleLogger
5
5
  module Devices
6
6
  class MemoryDevice
7
-
8
7
  attr_reader :logs
9
8
  attr_reader :status
10
9
 
@@ -0,0 +1,42 @@
1
+ # frozen_string_literal: true
2
+
3
+ module RubySmart
4
+ module SimpleLogger
5
+ module Devices
6
+ class NullDevice
7
+ attr_reader :status
8
+
9
+ def initialize
10
+ @status = true
11
+ end
12
+
13
+ def write(*)
14
+ nil
15
+ end
16
+
17
+ alias_method :<<, :write
18
+
19
+ # disables writing
20
+ def close
21
+ @status = false
22
+ end
23
+
24
+ # enables writing
25
+ def reopen
26
+ @status = true
27
+ end
28
+
29
+ # clears all logs
30
+ def clear!
31
+ nil
32
+ end
33
+
34
+ # returns logs
35
+ # @return [Array] logs
36
+ def logs
37
+ []
38
+ end
39
+ end
40
+ end
41
+ end
42
+ end
@@ -132,11 +132,19 @@ module RubySmart
132
132
  when nil # builtin is nil - resolve optimal device for current environment
133
133
  if ::ThreadInfo.stdout?
134
134
  _resolve_device(:stdout, opts)
135
+ elsif ::ThreadInfo.debugger?
136
+ _resolve_device(:debugger, opts)
135
137
  elsif ::ThreadInfo.rails? && ::Rails.logger
136
138
  _resolve_device(:rails, opts)
137
139
  else
138
140
  _resolve_device(:memory, opts)
139
141
  end
142
+ when :null
143
+ ::RubySmart::SimpleLogger::Devices::NullDevice.new
144
+ when :debugger
145
+ raise "Unable to build SimpleLogger with 'debugger' builtin for not initialized Debugger!" unless ThreadInfo.debugger?
146
+
147
+ _resolve_device(::Debugger.logger, opts)
140
148
  when :stdout
141
149
  STDOUT
142
150
  when :stderr
@@ -148,9 +156,9 @@ module RubySmart
148
156
  if ThreadInfo.console? && ::Rails.logger.instance_variable_get(:@logdev).dev != STDOUT
149
157
  ::RubySmart::SimpleLogger::Devices::MultiDevice
150
158
  .register(_resolve_device(:stdout, opts))
151
- .register(::Rails.logger.instance_variable_get(:@logdev).dev)
159
+ .register(_resolve_device(::Rails.logger, opts))
152
160
  else
153
- ::Rails.logger.instance_variable_get(:@logdev).dev
161
+ _resolve_device(::Rails.logger, opts)
154
162
  end
155
163
  when :proc
156
164
  # force overwrite opts
@@ -171,6 +179,8 @@ module RubySmart
171
179
  # force overwrite opts
172
180
  opts[:clr] = false
173
181
  _logdev(opts, builtin)
182
+ when ::Logger
183
+ builtin.instance_variable_get(:@logdev).dev
174
184
  else
175
185
  _logdev(opts, builtin)
176
186
  end
@@ -13,17 +13,25 @@ module RubySmart
13
13
  # @option [String] :char - the character to be used as mask
14
14
  # @option [Integer] :length - the mask length (amount of mask chars be line)
15
15
  # @option [Symbol] :clr - the color to be used by printing the mask
16
- self.mask = { char: '=', length: 100, clr: :blue }
16
+ self.mask = { char: '=', length: 120, clr: :blue }
17
17
  end
18
18
  end
19
19
 
20
20
  module ClassMethods
21
21
  def mask
22
- class_variable_get('@@mask')
22
+ @mask
23
23
  end
24
24
 
25
25
  def mask=(mask)
26
- class_variable_set('@@mask', mask)
26
+ @mask = mask
27
+ end
28
+
29
+ # prevents to overwrite parent class through inheriting subclasses
30
+ def inherited(subclass)
31
+ super
32
+
33
+ # dup existing values
34
+ subclass.mask = self.mask.dup
27
35
  end
28
36
  end
29
37
 
@@ -9,7 +9,7 @@ module RubySmart
9
9
 
10
10
  module VERSION
11
11
  MAJOR = 1
12
- MINOR = 3
12
+ MINOR = 4
13
13
  TINY = 0
14
14
  PRE = nil
15
15
 
@@ -11,6 +11,7 @@ require_relative 'extensions/timer'
11
11
 
12
12
  require_relative 'devices/memory_device'
13
13
  require_relative 'devices/multi_device'
14
+ require_relative 'devices/null_device'
14
15
  require_relative 'devices/proc_device'
15
16
 
16
17
  require_relative 'formatter'
@@ -47,7 +47,7 @@ module RubySmart
47
47
  # > ================================================ [Error] =================================================
48
48
  # > DATA
49
49
  # > ==========================================================================================================
50
- base.scene :error, { level: :error, mask: { clr: :red }, payload: [[:mask, ' [%{subject}] '], :__data__, :mask] } do |data,*args|
50
+ base.scene :error, { level: :error, mask: { clr: :red }, payload: [[:mask, ' [%{subject}] '], :__data__, :mask] } do |data, *args|
51
51
  subject, opts = _scene_subject_with_opts(args, 'Error')
52
52
  self.log data, _scene_opt(:error, { subject: subject }, opts)
53
53
  end
@@ -353,6 +353,32 @@ module RubySmart
353
353
 
354
354
  true
355
355
  end
356
+
357
+ # model method
358
+ # log level @ error/success/info
359
+ # prints: ActiveRecord::Base related data, depending on the models "save" state (also shows possible errors)
360
+ base.scene :model do |model, opts = {}|
361
+ # build model-logging string
362
+ mdl_string = "#{model.id.present? ? "##{model.id} - " : ''}#{model.to_s[0..49]}"
363
+
364
+ # resolve model's status
365
+ status = ((model.persisted? && model.errors.empty?) ? (model.previous_changes.blank? ? :skipped : :success) : :error)
366
+
367
+ # switch between status
368
+ case status
369
+ when :success
370
+ # show verbose logging for updated records
371
+ if opts[:verbose] != false && !model.previously_new_record?
372
+ log(:success, "#{mdl_string} (#{model.previous_changes.inspect})", tag: "#{model.class.name.upcase}|UPDATED")
373
+ else
374
+ log(:success, mdl_string, tag: "#{model.class.name.upcase}|#{(model.previously_new_record? ? 'CREATED' : 'UPDATED')}")
375
+ end
376
+ when :error
377
+ log(:error, "#{mdl_string} (#{model.errors.full_messages.join(', ').presence || '-'})", tag: "#{model.class.name.upcase}|ERROR")
378
+ else
379
+ log(:info, mdl_string, tag: "#{model.class.name.upcase}|#{status}")
380
+ end
381
+ end
356
382
  end
357
383
  end
358
384
  end
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.authors = ['Tobias Gonsior']
9
9
  spec.email = ['info@ruby-smart.org']
10
10
 
11
- spec.summary = "A simple, multifunctional logging library for Ruby."
11
+ spec.summary = "A simple, multifunctional logging library for Ruby (and Rails)."
12
12
  spec.description = <<~DESC
13
13
  RubySmart::SimpleLogger is a fast, customizable logging library with multi-device support,
14
14
  special (PRE-defined) scenes for better logging visibility.
@@ -33,7 +33,7 @@ Gem::Specification.new do |spec|
33
33
 
34
34
  spec.require_paths = ['lib']
35
35
 
36
- spec.add_dependency 'ruby_smart-support', '~> 1.2'
36
+ spec.add_dependency 'ruby_smart-support', '~> 1.5'
37
37
 
38
38
  spec.add_development_dependency 'awesome_print', '~> 1.9'
39
39
  spec.add_development_dependency 'coveralls_reborn', '~> 0.25'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby_smart-simple_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.4.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Gonsior
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-08-14 00:00:00.000000000 Z
11
+ date: 2024-07-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby_smart-support
@@ -16,14 +16,14 @@ dependencies:
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.2'
19
+ version: '1.5'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.2'
26
+ version: '1.5'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: awesome_print
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -135,19 +135,20 @@ files:
135
135
  - ".rspec"
136
136
  - ".yardopts"
137
137
  - Gemfile
138
+ - LICENSE.txt
138
139
  - README.md
139
140
  - Rakefile
140
141
  - bin/console
141
142
  - bin/setup
142
143
  - docs/CHANGELOG.md
143
144
  - docs/CODE_OF_CONDUCT.md
144
- - docs/LICENSE.txt
145
145
  - lib/ruby_smart-debugger.rb
146
146
  - lib/ruby_smart-simple_logger.rb
147
147
  - lib/ruby_smart/simple_logger.rb
148
148
  - lib/ruby_smart/simple_logger/core_ext/ruby/string.rb
149
149
  - lib/ruby_smart/simple_logger/devices/memory_device.rb
150
150
  - lib/ruby_smart/simple_logger/devices/multi_device.rb
151
+ - lib/ruby_smart/simple_logger/devices/null_device.rb
151
152
  - lib/ruby_smart/simple_logger/devices/proc_device.rb
152
153
  - lib/ruby_smart/simple_logger/extensions/helper.rb
153
154
  - lib/ruby_smart/simple_logger/extensions/logs.rb
@@ -189,8 +190,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
189
190
  - !ruby/object:Gem::Version
190
191
  version: '0'
191
192
  requirements: []
192
- rubygems_version: 3.4.10
193
+ rubygems_version: 3.5.14
193
194
  signing_key:
194
195
  specification_version: 4
195
- summary: A simple, multifunctional logging library for Ruby.
196
+ summary: A simple, multifunctional logging library for Ruby (and Rails).
196
197
  test_files: []
File without changes