ruby_smart-simple_logger 1.5.2 → 1.6.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 +4 -4
- data/README.md +83 -5
- data/docs/CHANGELOG.md +11 -0
- data/lib/ruby_smart/simple_logger/extensions/helper.rb +110 -86
- data/lib/ruby_smart/simple_logger/gem_version.rb +2 -2
- data/lib/ruby_smart/simple_logger/logger.rb +27 -7
- data/lib/ruby_smart/simple_logger/scenes.rb +24 -24
- metadata +3 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5f377784d8f7f47e7e2e6e8db6af4a59f18141a46dc4a02c6a1e7d065b40d660
|
4
|
+
data.tar.gz: 23bceaf895ef087fb54620a3b8b09c8c1952da685ce862c8eaafff52bf7756fa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c1de42c4b096d61f6c9e085c613cb3d70f82c6aae3abdb4d2f4e488d4eb665576a37d68b22d23fb57d15d6bebbe4231f533c34b12e1e3a079ccb4d6f540acb2
|
7
|
+
data.tar.gz: e6eef91be3f2e57d15401b9ae6d4768265376957009b3934122d21456b7ad16c1c2322b35aa12b658af027e6407c252a5e5d49cf745ed32a995e28ab78b97b76
|
data/README.md
CHANGED
@@ -39,6 +39,7 @@ Or install it yourself as:
|
|
39
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
|
+
* Debug / Debase compatibility
|
42
43
|
|
43
44
|
-----
|
44
45
|
|
@@ -789,12 +790,89 @@ end
|
|
789
790
|
# ╚ END ❯ Process Alpha (0.001036969)
|
790
791
|
```
|
791
792
|
|
792
|
-
###
|
793
|
+
### model(mdl, opts)
|
794
|
+
Useful for rails applications to debug or log a save _(create/update)_ result of a model.
|
795
|
+
The `model` method logs in three different scenes `SUCCESS ERROR INFO`, depending on the models state: created, updated, error, skipped
|
793
796
|
|
794
|
-
|
795
|
-
|
796
|
-
|
797
|
-
|
797
|
+
```ruby
|
798
|
+
require 'simple_logger'
|
799
|
+
l = SimpleLogger.new(:stdout, payload: false)
|
800
|
+
|
801
|
+
# create a model and save it (with validation errors)
|
802
|
+
mdl = User.new first_name: 'Max'
|
803
|
+
mdl.save
|
804
|
+
|
805
|
+
# log the result
|
806
|
+
l.model(mdl)
|
807
|
+
|
808
|
+
# creates an ERROR of:
|
809
|
+
# [USER|ERROR] Max (E-Mail is invalid, Username is invalid)
|
810
|
+
|
811
|
+
# ------------------------------------------------------------------------------------------
|
812
|
+
|
813
|
+
# update the model to prevent validation errors
|
814
|
+
mdl.username = 'test'
|
815
|
+
mdl.email = 'max@test.x'
|
816
|
+
mdl.save
|
817
|
+
|
818
|
+
# creates an SUCCESS of:
|
819
|
+
# [USER|CREATED] #1 - Max
|
820
|
+
|
821
|
+
# ------------------------------------------------------------------------------------------
|
822
|
+
|
823
|
+
# update the model
|
824
|
+
mdl.update(username: 'tester')
|
825
|
+
|
826
|
+
# creates an SUCCESS of:
|
827
|
+
# [USER|UPDATED] #1 - Max
|
828
|
+
|
829
|
+
# ------------------------------------------------------------------------------------------
|
830
|
+
|
831
|
+
# update the model again (without any change)
|
832
|
+
mdl.update(username: 'tester')
|
833
|
+
|
834
|
+
# creates an INFO of:
|
835
|
+
# [USER|SKIPPED] #1 - Max
|
836
|
+
```
|
837
|
+
|
838
|
+
### line(data, opts)
|
839
|
+
Prints just a line with data and line-break _(for payloads)_
|
840
|
+
|
841
|
+
```ruby
|
842
|
+
require 'simple_logger'
|
843
|
+
l = SimpleLogger.new(:stdout)
|
844
|
+
|
845
|
+
l.line "some example line of DATA"
|
846
|
+
l.print "other example"
|
847
|
+
# > some example line of DATA
|
848
|
+
# > other example
|
849
|
+
# >
|
850
|
+
```
|
851
|
+
|
852
|
+
### print(data, opts)
|
853
|
+
Prints just data without line-break
|
854
|
+
|
855
|
+
```ruby
|
856
|
+
require 'simple_logger'
|
857
|
+
l = SimpleLogger.new(:stdout)
|
858
|
+
|
859
|
+
l.print "some example line of DATA"
|
860
|
+
l.print "other example"
|
861
|
+
# > some example line of DATAother example
|
862
|
+
```
|
863
|
+
|
864
|
+
|
865
|
+
### nl(opts)
|
866
|
+
Prints just a line-break.
|
867
|
+
|
868
|
+
```ruby
|
869
|
+
require 'simple_logger'
|
870
|
+
l = SimpleLogger.new(:stdout)
|
871
|
+
|
872
|
+
l.nl
|
873
|
+
# >
|
874
|
+
# >
|
875
|
+
```
|
798
876
|
|
799
877
|
-----
|
800
878
|
|
data/docs/CHANGELOG.md
CHANGED
@@ -1,5 +1,16 @@
|
|
1
1
|
# RubySmart::SimpleLogger - CHANGELOG
|
2
2
|
|
3
|
+
## [1.6.0] - 2025-06-13
|
4
|
+
* **[add]** `Proc` to builtins
|
5
|
+
* **[add]** better specs
|
6
|
+
* **[ref]** initialization process _(simplify, move instance-assignments to `#initialize`, rename \_opts_x to assign_x)_
|
7
|
+
* **[fix]** `Debase.logger` rewriting for Ruby 3.x _(Debase.logger is a proc instead of a Logger / STDOUT)_
|
8
|
+
|
9
|
+
## [1.5.3] - 2024-09-16
|
10
|
+
* **[fix]** scene `job`-, `sub_job`-methods not working with provided block
|
11
|
+
* **[fix]** scene `result`-methods not printing boolean results (also fixes exception for boolean/numeric results)
|
12
|
+
* **[fix]** fix color helper `_res_clr`-method to not raise for transforming to symbol
|
13
|
+
|
3
14
|
## [1.5.2] - 2024-09-12
|
4
15
|
* **[fix]** swap 'verbose' logging for `model` scene _(now uses FALSE by default)_
|
5
16
|
|
@@ -13,7 +13,7 @@ module RubySmart
|
|
13
13
|
|
14
14
|
# set / overwrite default opts
|
15
15
|
# @param [Hash] opts
|
16
|
-
def
|
16
|
+
def assign_defaults!(opts)
|
17
17
|
# -- level ---------------------------------------------------------------------------------------------------
|
18
18
|
|
19
19
|
# initialize a default rails-dependent output
|
@@ -37,32 +37,17 @@ module RubySmart
|
|
37
37
|
self.mask(length: ::ThreadInfo.winsize[1])
|
38
38
|
end
|
39
39
|
|
40
|
-
#
|
41
|
-
|
42
|
-
# ignore payload and send data directly to the logdev
|
43
|
-
@ignore_payload = true if @ignore_payload.nil? && opts[:payload] == false
|
44
|
-
|
45
|
-
# ignore processed logging and send data without 'leveling' & PCD-char to the logdev
|
46
|
-
@ignore_processed = true if @ignore_processed.nil? && opts[:processed] == false
|
47
|
-
|
48
|
-
# ignore tagged logging and send data without 'tags' to the logdev
|
49
|
-
@ignore_tagged = true if @ignore_tagged.nil? && opts[:tagged] == false
|
50
|
-
|
51
|
-
# set custom inspector (used for data inspection)
|
52
|
-
# 'disable' inspector, if false was provided - which simply results in +#to_s+
|
53
|
-
@inspector = (opts[:inspect] == false) ? :to_s : opts[:inspector]
|
54
|
-
|
55
|
-
# prevent to return any data
|
40
|
+
# prevent returning any data
|
56
41
|
nil
|
57
42
|
end
|
58
43
|
|
59
|
-
# enhance provided opts with +:
|
44
|
+
# enhance provided opts with +:logdev+.
|
60
45
|
# opts may be manipulated by resolved device
|
61
46
|
# does not return any data.
|
62
47
|
# @param [Hash] opts
|
63
|
-
def
|
64
|
-
# check for already existing +
|
65
|
-
return if opts[:
|
48
|
+
def assign_logdev!(opts)
|
49
|
+
# check for already existing +logdev+
|
50
|
+
return if opts[:logdev]
|
66
51
|
|
67
52
|
# remove builtin key from opts and force an array
|
68
53
|
builtins = Array(opts.delete(:builtin))
|
@@ -77,20 +62,23 @@ module RubySmart
|
|
77
62
|
|
78
63
|
# don't create multi-device for a single (or +nil+) builtin
|
79
64
|
if builtins.length < 2
|
80
|
-
opts[:
|
65
|
+
opts[:logdev] = _resolve_device(builtins[0], opts)
|
81
66
|
else
|
82
|
-
opts[:
|
67
|
+
opts[:logdev] = ::RubySmart::SimpleLogger::Devices::MultiDevice.new
|
83
68
|
builtins.each do |builtin|
|
84
69
|
# IMPORTANT: dup, original hash to prevent reference manipulation (on the TOP-level, only)
|
85
70
|
builtin_opts = opts.dup
|
86
|
-
opts[:
|
71
|
+
opts[:logdev].register(_resolve_device(builtin, builtin_opts), _resolve_formatter(builtin_opts))
|
72
|
+
|
73
|
+
# disable payload, if any is disabled
|
74
|
+
opts[:payload] = false if builtin_opts[:payload] == false
|
87
75
|
end
|
88
76
|
|
89
77
|
# force 'passthrough', as format, since this is required for multi-devices
|
90
78
|
opts[:format] = :passthrough
|
91
79
|
end
|
92
80
|
|
93
|
-
# prevent
|
81
|
+
# prevent returning any data
|
94
82
|
nil
|
95
83
|
end
|
96
84
|
|
@@ -98,13 +86,13 @@ module RubySmart
|
|
98
86
|
# opts may be manipulated by resolved formatter
|
99
87
|
# does not return any data.
|
100
88
|
# @param [Hash] opts
|
101
|
-
def
|
89
|
+
def assign_formatter!(opts)
|
102
90
|
# check for already existing +formatter+
|
103
91
|
return if opts[:formatter]
|
104
92
|
|
105
93
|
opts[:formatter] = _resolve_formatter(opts)
|
106
94
|
|
107
|
-
# prevent
|
95
|
+
# prevent returning any data
|
108
96
|
nil
|
109
97
|
end
|
110
98
|
|
@@ -116,7 +104,7 @@ module RubySmart
|
|
116
104
|
opts[:format] ||= :plain
|
117
105
|
|
118
106
|
# fix nl - which depends on other opts
|
119
|
-
opts[:nl]
|
107
|
+
opts[:nl] = _nl(opts)
|
120
108
|
|
121
109
|
# fix clr
|
122
110
|
opts[:clr] = true if opts[:clr].nil?
|
@@ -125,12 +113,17 @@ module RubySmart
|
|
125
113
|
end
|
126
114
|
|
127
115
|
# resolves & returns device from builtin & provided opts
|
128
|
-
# @param [Object] builtin
|
116
|
+
# @param [Object,nil] builtin
|
129
117
|
# @param [Hash] opts
|
130
118
|
def _resolve_device(builtin, opts)
|
119
|
+
# in case the provided *builtin* already responds to +write+, return it
|
120
|
+
return builtin if builtin.respond_to?(:write)
|
121
|
+
|
131
122
|
case builtin
|
132
123
|
when nil # builtin is nil - resolve optimal device for current environment
|
133
|
-
if
|
124
|
+
if opts.key?(:device)
|
125
|
+
_resolve_device(opts.delete(:device), opts)
|
126
|
+
elsif ::ThreadInfo.stdout?
|
134
127
|
_resolve_device(:stdout, opts)
|
135
128
|
elsif ::ThreadInfo.debugger?
|
136
129
|
_resolve_device(:debugger, opts)
|
@@ -144,7 +137,13 @@ module RubySmart
|
|
144
137
|
when :debugger
|
145
138
|
raise "Unable to build SimpleLogger with 'debugger' builtin for not initialized Debugger!" unless ThreadInfo.debugger?
|
146
139
|
|
147
|
-
|
140
|
+
# since some IDEs did a Debase rewriting for Ruby 3.x, the logger is a Proc instead of a Logger instance
|
141
|
+
if ::Debugger.logger.is_a?(Proc)
|
142
|
+
opts[:format] = :plain # only the data string is forwarded to the proc
|
143
|
+
::RubySmart::SimpleLogger::Devices::ProcDevice.new(::Debugger.logger)
|
144
|
+
else
|
145
|
+
_resolve_device(::Debugger.logger, opts)
|
146
|
+
end
|
148
147
|
when :stdout
|
149
148
|
STDOUT
|
150
149
|
when :stderr
|
@@ -161,84 +160,103 @@ module RubySmart
|
|
161
160
|
_resolve_device(::Rails.logger, opts)
|
162
161
|
end
|
163
162
|
when :proc
|
164
|
-
#
|
165
|
-
|
166
|
-
opts[:nl] = false
|
167
|
-
opts[:format] = :passthrough
|
168
|
-
|
169
|
-
::RubySmart::SimpleLogger::Devices::ProcDevice.new(opts.delete(:proc))
|
163
|
+
# slurp the proc and call the '_resolve_device' again
|
164
|
+
_resolve_device(opts.delete(:proc), opts)
|
170
165
|
when :memory
|
171
166
|
# force overwrite opts
|
172
|
-
|
173
|
-
opts[:format]
|
167
|
+
opts[:payload] = false
|
168
|
+
opts[:format] = :memory
|
174
169
|
# no color logging for memory devices
|
175
170
|
opts[:clr] = false
|
176
171
|
|
177
172
|
::RubySmart::SimpleLogger::Devices::MemoryDevice.new
|
178
|
-
when
|
173
|
+
when Proc
|
179
174
|
# force overwrite opts
|
180
|
-
opts[:
|
181
|
-
|
182
|
-
|
183
|
-
builtin.instance_variable_get(:@logdev).dev
|
184
|
-
else
|
185
|
-
_logdev(opts, builtin)
|
186
|
-
end
|
187
|
-
end
|
188
|
-
|
189
|
-
# resolve the final log-device from provided param
|
190
|
-
# @param [Hash] opts
|
191
|
-
# @param [Object] device
|
192
|
-
# @return [:Logger::LogDevice]
|
193
|
-
def _logdev(opts, device = nil)
|
194
|
-
device ||= opts.delete(:device)
|
175
|
+
opts[:payload] = false
|
176
|
+
opts[:nl] = false
|
177
|
+
opts[:format] = :passthrough
|
195
178
|
|
196
|
-
|
197
|
-
|
179
|
+
::RubySmart::SimpleLogger::Devices::ProcDevice.new(builtin)
|
180
|
+
when Module
|
181
|
+
# no color logging for logfiles
|
182
|
+
opts[:clr] = false
|
198
183
|
|
199
|
-
|
184
|
+
logfile = _underscore(builtin.to_s) + '.log'
|
200
185
|
|
201
|
-
|
202
|
-
|
203
|
-
|
204
|
-
|
205
|
-
|
206
|
-
# check for rails
|
207
|
-
if ::ThreadInfo.rails?
|
208
|
-
file_location = File.join(Rails.root, 'log', logfile)
|
209
|
-
else
|
210
|
-
file_location = File.join('log', logfile)
|
211
|
-
end
|
186
|
+
file_location = if ::ThreadInfo.rails? # check for rails
|
187
|
+
File.join(::Rails.root, 'log', logfile)
|
188
|
+
else
|
189
|
+
File.join('log', logfile)
|
190
|
+
end
|
212
191
|
|
213
192
|
# resolve path to create a folder
|
214
193
|
file_path = File.dirname(file_location)
|
215
194
|
FileUtils.mkdir_p(file_path) unless File.directory?(file_path)
|
216
195
|
|
217
|
-
# the
|
218
|
-
file_location
|
196
|
+
# resolve new logdev with the provided options
|
197
|
+
_logdev(file_location, opts)
|
219
198
|
when String
|
220
|
-
|
199
|
+
# no color logging for logfiles
|
200
|
+
opts[:clr] = false
|
201
|
+
|
202
|
+
logfile = if builtin[-4..-1] == '.log'
|
203
|
+
builtin
|
204
|
+
else
|
205
|
+
builtin + '.log'
|
206
|
+
end
|
207
|
+
|
208
|
+
file_location = if builtin[0] == '/'
|
209
|
+
builtin
|
210
|
+
elsif ::ThreadInfo.rails?
|
211
|
+
File.join(Rails.root, 'log', logfile)
|
212
|
+
else
|
213
|
+
File.join('log', logfile)
|
214
|
+
end
|
221
215
|
|
222
216
|
# resolve path to create a folder
|
223
217
|
file_path = File.dirname(file_location)
|
224
218
|
FileUtils.mkdir_p(file_path) unless File.directory?(file_path)
|
225
219
|
|
226
|
-
|
220
|
+
# resolve new logdev with the provided options
|
221
|
+
_logdev(file_location, opts)
|
222
|
+
when ::Logger
|
223
|
+
# resolve the logdev from the provided logger
|
224
|
+
builtin.instance_variable_get(:@logdev).dev
|
227
225
|
else
|
228
|
-
raise "Unable to build SimpleLogger! The provided device '#{
|
226
|
+
raise "Unable to build SimpleLogger! The provided device '#{builtin}' must respond to 'write'!"
|
229
227
|
end
|
228
|
+
end
|
230
229
|
|
230
|
+
# Creates and configures a new instance of Logger::LogDevice based on the provided file location
|
231
|
+
# and optional settings.
|
232
|
+
#
|
233
|
+
# The configuration differs slightly based on the Ruby version being used. For Ruby versions
|
234
|
+
# prior to 2.7, the options `:binmode` is omitted as it is not supported. For Ruby 2.7 and newer,
|
235
|
+
# the `:binmode` option is included.
|
236
|
+
#
|
237
|
+
# @param [String] file_location - the file path where the log will be written.
|
238
|
+
# @param [Hash] opts
|
239
|
+
# A hash of options to configure the log device:
|
240
|
+
# - `:shift_age` (default: 0) - Specifies the number of old log files to retain.
|
241
|
+
# - `:shift_size` (default: 1048576, 1MB) - Specifies the maximum size of the log file,
|
242
|
+
# after which the file will be rotated.
|
243
|
+
# - `:shift_period_suffix` - A string specifying the date format for rotated files (optional).
|
244
|
+
# - `:binmode` (Ruby >= 2.7 only) - Enables binary mode explicitly if set to `true`.
|
245
|
+
#
|
246
|
+
# @return [Logger::LogDevice]
|
247
|
+
# Returns a newly configured instance of Logger::LogDevice.
|
248
|
+
def _logdev(file_location, opts)
|
231
249
|
if GemInfo.match?(RUBY_VERSION, '< 2.7')
|
232
250
|
::Logger::LogDevice.new(file_location,
|
233
|
-
shift_age:
|
234
|
-
shift_size:
|
251
|
+
shift_age: opts[:shift_age] || 0,
|
252
|
+
shift_size: opts[:shift_size] || 1048576,
|
235
253
|
shift_period_suffix: opts[:shift_period_suffix])
|
236
254
|
else
|
237
255
|
::Logger::LogDevice.new(file_location,
|
238
|
-
shift_age:
|
239
|
-
shift_size:
|
256
|
+
shift_age: opts[:shift_age] || 0,
|
257
|
+
shift_size: opts[:shift_size] || 1048576,
|
240
258
|
shift_period_suffix: opts[:shift_period_suffix],
|
241
|
-
binmode:
|
259
|
+
binmode: opts[:binmode])
|
242
260
|
end
|
243
261
|
end
|
244
262
|
|
@@ -356,18 +374,24 @@ module RubySmart
|
|
356
374
|
# > :yellow
|
357
375
|
#
|
358
376
|
# _res_clr('not_really_a_color')
|
359
|
-
# > :
|
377
|
+
# > :green
|
360
378
|
#
|
361
|
-
# @param [Boolean, String, Integer, Symbol]
|
379
|
+
# @param [Boolean, String, Integer, Symbol] args
|
362
380
|
# @return [Symbol] color
|
363
|
-
def _res_clr(
|
364
|
-
case
|
365
|
-
when true, 1, '1'
|
381
|
+
def _res_clr(*args)
|
382
|
+
case (res = args.compact.first)
|
383
|
+
when true, 'true', 1, '1'
|
366
384
|
:green
|
367
|
-
when false, 0, '0'
|
385
|
+
when false, 'false', 0, '0', ''
|
368
386
|
:red
|
387
|
+
when '-', nil
|
388
|
+
:yellow
|
389
|
+
when String
|
390
|
+
:green
|
391
|
+
when Symbol
|
392
|
+
res
|
369
393
|
else
|
370
|
-
|
394
|
+
:grey
|
371
395
|
end
|
372
396
|
end
|
373
397
|
end
|
@@ -47,24 +47,44 @@ module RubySmart
|
|
47
47
|
# @option args[Symbol,Array] <builtin> - provide a builtin, either a single symbol or array of symbols
|
48
48
|
# @option args[Hash] <options> - provide custom options
|
49
49
|
def initialize(*args)
|
50
|
+
# transform args to opts
|
50
51
|
opts = args.last.is_a?(Hash) ? args.pop : {}
|
51
52
|
opts[:builtin] = args if args.length > 0
|
52
53
|
|
53
|
-
#
|
54
|
-
|
55
|
-
_opts_formatter!(opts)
|
54
|
+
# assign logdev to opts
|
55
|
+
assign_logdev!(opts)
|
56
56
|
|
57
|
-
#
|
58
|
-
|
57
|
+
# assign formatter to opts
|
58
|
+
assign_formatter!(opts)
|
59
|
+
|
60
|
+
# assign default opts
|
61
|
+
assign_defaults!(opts)
|
59
62
|
|
60
63
|
# initialize with a nil +logdev+ to prevent any nested +LogDevice+ creation.
|
61
64
|
# we already arranged device & formatter to be able to respond to ther required methods
|
62
65
|
super(nil)
|
63
66
|
|
64
|
-
# set
|
67
|
+
# level must be set through the *_level* method, to prevent invalid values
|
65
68
|
self.level = opts[:level]
|
69
|
+
|
70
|
+
# use the provided formatter
|
66
71
|
self.formatter = opts[:formatter]
|
67
|
-
|
72
|
+
|
73
|
+
# ignore payload and send data directly to the logdev
|
74
|
+
@ignore_payload = true if opts[:payload] == false
|
75
|
+
|
76
|
+
# ignore processed logging and send data without 'leveling' & PCD-char to the logdev
|
77
|
+
@ignore_processed = true if opts[:processed] == false
|
78
|
+
|
79
|
+
# ignore tagged logging and send data without 'tags' to the logdev
|
80
|
+
@ignore_tagged = true if opts[:tagged] == false
|
81
|
+
|
82
|
+
# set custom inspector (used for data inspection)
|
83
|
+
# 'disable' inspector, if false was provided - which simply results in +#to_s+
|
84
|
+
@inspector = (opts[:inspect] == false) ? :to_s : opts[:inspector]
|
85
|
+
|
86
|
+
# set resolved logdev
|
87
|
+
@logdev = opts[:logdev]
|
68
88
|
end
|
69
89
|
|
70
90
|
# overwrite level setter, to accept every available (also newly defined) Severity
|
@@ -85,9 +85,9 @@ module RubySmart
|
|
85
85
|
# log level @ debug
|
86
86
|
# prints: prettified subject
|
87
87
|
#
|
88
|
-
# >
|
89
|
-
# >
|
90
|
-
# >
|
88
|
+
# > ========================================================================================================================
|
89
|
+
# > ======================================================= <Subject> ======================================================
|
90
|
+
# > ========================================================================================================================
|
91
91
|
base.scene :header, { level: :debug, payload: [:mask, [:mask, ' <%{subject}> '], :mask] } do |subject, **opts|
|
92
92
|
# autostart a timer method, if required
|
93
93
|
self.timer(:start, :default) if opts[:timer]
|
@@ -99,9 +99,9 @@ module RubySmart
|
|
99
99
|
# log level @ debug
|
100
100
|
# prints: prettified subject
|
101
101
|
#
|
102
|
-
# >
|
103
|
-
# >
|
104
|
-
# >
|
102
|
+
# > ========================================================================================================================
|
103
|
+
# > ======================================================= >Subject< ======================================================
|
104
|
+
# > ========================================================================================================================
|
105
105
|
base.scene :footer, { level: :debug, payload: [:mask, [:mask, ' >%{subject}< '], :mask] } do |subject, **opts|
|
106
106
|
self.log nil, _scene_opts(:footer, subject: subject.to_s, **opts)
|
107
107
|
|
@@ -113,9 +113,9 @@ module RubySmart
|
|
113
113
|
# log level @ debug
|
114
114
|
# prints: prettified subject
|
115
115
|
#
|
116
|
-
# >
|
117
|
-
# >
|
118
|
-
# >
|
116
|
+
# > -----------------------------------------------------------------------------------------------
|
117
|
+
# > #------------------------------------------ Subject ------------------------------------------#
|
118
|
+
# > -----------------------------------------------------------------------------------------------
|
119
119
|
base.scene :topic, { level: :debug, mask: { char: '-', length: 95, clr: :blueish }, payload: [:mask, [:mask, '%{title}'], :mask] } do |subject, **opts|
|
120
120
|
opts = _scene_opts(:topic, **opts)
|
121
121
|
txt = " #{subject} ".center(opts[:mask][:length] - 2, opts[:mask][:char])
|
@@ -129,7 +129,7 @@ module RubySmart
|
|
129
129
|
# prints: prettified, colored subject
|
130
130
|
#
|
131
131
|
# > # Subject
|
132
|
-
# >
|
132
|
+
# > -------------------------------------------------------------------------------------
|
133
133
|
base.scene :theme, { level: :debug, clr: :purple, mask: { char: '-', length: 85, clr: :purple }, payload: [[:txt, '# %{subject}'], :mask] } do |subject, **opts|
|
134
134
|
self.log nil, _scene_opts(:theme, subject: subject.to_s, **opts)
|
135
135
|
end
|
@@ -138,19 +138,18 @@ module RubySmart
|
|
138
138
|
# log level @ debug
|
139
139
|
# prints: prettified, colored result
|
140
140
|
#
|
141
|
-
# >
|
141
|
+
# > -------------------------------------------------------------------------------------
|
142
142
|
# > -> Result
|
143
143
|
# >
|
144
144
|
base.scene :theme_result, { level: :debug, mask: { char: '-', length: 85, clr: :purple }, payload: [:mask, [:txt, '-> %{result}'], ''] } do |result, status = nil, **opts|
|
145
|
-
|
146
|
-
self.log nil, _scene_opts(:theme_result, result: result, clr: _res_clr(res_or_clr), **opts)
|
145
|
+
self.log nil, _scene_opts(:theme_result, result: result, clr: _res_clr(status, result), **opts)
|
147
146
|
end
|
148
147
|
|
149
148
|
# theme_line method
|
150
149
|
# log level @ debug
|
151
150
|
# prints: colored line with no text
|
152
151
|
#
|
153
|
-
# >
|
152
|
+
# > -------------------------------------------------------------------------------------
|
154
153
|
base.scene :theme_line, { level: :debug, mask: { char: '-', length: 85, clr: :purple }, payload: [:mask] } do |**opts|
|
155
154
|
self.log nil, _scene_opts(:theme_line, **opts)
|
156
155
|
end
|
@@ -171,10 +170,10 @@ module RubySmart
|
|
171
170
|
# calls the result method if a block was provided
|
172
171
|
#
|
173
172
|
# > - Job name =>
|
174
|
-
#
|
173
|
+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ <- 64 chars
|
175
174
|
base.scene :job, { level: :debug, clr: :cyan, nl: false, length: 64, payload: [[:concat, ['- ', [:txt, '%{name}'], ' => ']]] } do |name, **opts, &block|
|
176
175
|
self.log nil, _scene_opts(:job, name: name, **opts)
|
177
|
-
self.result(*block.call) if
|
176
|
+
self.result(*block.call) if block
|
178
177
|
end
|
179
178
|
|
180
179
|
# sub_job method
|
@@ -183,10 +182,10 @@ module RubySmart
|
|
183
182
|
# calls the result method if a block was provided
|
184
183
|
#
|
185
184
|
# > * Subjob name =>
|
186
|
-
#
|
185
|
+
# ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ <- 62 chars
|
187
186
|
base.scene :sub_job, { level: :debug, clr: :cyan, nl: false, length: 62, payload: [[:concat, [' * ', [:txt, '%{name}'], ' => ']]] } do |name, **opts, &block|
|
188
187
|
self.log nil, _scene_opts(:sub_job, name: name, **opts)
|
189
|
-
self.result(*block.call) if
|
188
|
+
self.result(*block.call) if block
|
190
189
|
end
|
191
190
|
|
192
191
|
# result method
|
@@ -195,8 +194,7 @@ module RubySmart
|
|
195
194
|
#
|
196
195
|
# > Result
|
197
196
|
base.scene :result, { level: :debug, payload: [[:txt, '%{result}']] } do |result, status = nil, **opts|
|
198
|
-
|
199
|
-
self.log nil, _scene_opts(:result, result: result, clr: _res_clr(res_or_clr), **opts)
|
197
|
+
self.log nil, _scene_opts(:result, result: result.to_s, clr: _res_clr(status, result), **opts)
|
200
198
|
end
|
201
199
|
|
202
200
|
# job_result method
|
@@ -257,12 +255,13 @@ module RubySmart
|
|
257
255
|
#
|
258
256
|
# > .FFF...??...F....F...F..???....F...??
|
259
257
|
base.scene :spec, { level: :debug, nl: false, payload: [[:txt, '%{result}']] } do |status, **opts|
|
260
|
-
result =
|
258
|
+
result = case status
|
259
|
+
when true
|
261
260
|
'.'
|
262
|
-
|
261
|
+
when false
|
263
262
|
'F'
|
264
263
|
else
|
265
|
-
status = :yellow
|
264
|
+
status = nil # IMPORTANT: reset to nil will enforce a 'yellow' color
|
266
265
|
'?'
|
267
266
|
end
|
268
267
|
self.log nil, _scene_opts(:spec, result: result, clr: _res_clr(status), **opts)
|
@@ -332,13 +331,14 @@ module RubySmart
|
|
332
331
|
end
|
333
332
|
rescue => e
|
334
333
|
self.fatal("#{e.message} @ #{e.backtrace_locations&.first}") unless opts[:silent]
|
334
|
+
|
335
335
|
# reraise exception
|
336
336
|
raise
|
337
337
|
ensure
|
338
338
|
result_str ||= ''
|
339
339
|
|
340
340
|
# send END name with result & possible time as +data+ - the full log line is created through the +_pcd+ method.
|
341
|
-
self.log("#{name} #{result_str}#{(timer_key ? "(#{self.timer(:clear, timer_key, humanized: true)})" : '')}", _scene_opts(:processed, **opts, pcd: :end
|
341
|
+
self.log("#{name} #{result_str}#{(timer_key ? "(#{self.timer(:clear, timer_key, humanized: true)})" : '')}", _scene_opts(:processed, **opts, pcd: :end))
|
342
342
|
|
343
343
|
# reduce level
|
344
344
|
processed_lvl(:down)
|
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ruby_smart-simple_logger
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.6.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tobias Gonsior
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: ruby_smart-support
|
@@ -175,7 +174,6 @@ metadata:
|
|
175
174
|
documentation_uri: https://rubydoc.info/gems/ruby_smart-simple_logger
|
176
175
|
changelog_uri: https://github.com/ruby-smart/simple_logger/blob/main/docs/CHANGELOG.md
|
177
176
|
allowed_push_host: https://rubygems.org
|
178
|
-
post_install_message:
|
179
177
|
rdoc_options: []
|
180
178
|
require_paths:
|
181
179
|
- lib
|
@@ -190,8 +188,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
190
188
|
- !ruby/object:Gem::Version
|
191
189
|
version: '0'
|
192
190
|
requirements: []
|
193
|
-
rubygems_version: 3.
|
194
|
-
signing_key:
|
191
|
+
rubygems_version: 3.6.9
|
195
192
|
specification_version: 4
|
196
193
|
summary: A simple, multifunctional logging library for Ruby (and Rails).
|
197
194
|
test_files: []
|