ruby_smart-simple_logger 1.4.0 → 1.5.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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a08f3caf3bd643806e098079f29a399c3b99bf5d84528d1e2c034276b99ca2c9
|
4
|
+
data.tar.gz: 2a3caee2427ae5d8a51d7931749ac61c338af688c56993f48b9f412dffa85b98
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ccac78a543d4f6a20d15b86f044754fef1478bb7636607d228e359fa56093838dc1805bdc7147baa8845f97227cf06cc4ace949b3e14ec82745d2ee94c61c4bb
|
7
|
+
data.tar.gz: 44b6f4000abfff0f7b0f84eafd9caddf2708892576b6a8ed1d826490ae10795d8aa484ce70829884b23195cef7c52dce51e0801ef55af7321ca812e3527f2195
|
data/docs/CHANGELOG.md
CHANGED
@@ -1,5 +1,11 @@
|
|
1
1
|
# RubySmart::SimpleLogger - CHANGELOG
|
2
2
|
|
3
|
+
## [1.5.0] - 2024-09-12
|
4
|
+
* **[add]** `SimpleLogger.scene?`-method to check for registered scene options
|
5
|
+
* **[ref]** scene options to **keyword**-args _(**WARNING:** This may break existing calls to the scene methods)_
|
6
|
+
* **[fix]** `model` scene not calling related scene methods
|
7
|
+
* **[fix]** `subject` parameter for default severity-methods not cast as string _(now any object may be provided - which calls `#to_s` method)_
|
8
|
+
|
3
9
|
## [1.4.0] - 2024-07-31
|
4
10
|
* **[add]** 'null'-device / builtin
|
5
11
|
* **[add]** 'debugger'-builtin to send logs to the debugging gem
|
@@ -370,19 +370,6 @@ module RubySmart
|
|
370
370
|
res_or_clr.to_sym
|
371
371
|
end
|
372
372
|
end
|
373
|
-
|
374
|
-
# resolves subject & opts from provided args.
|
375
|
-
# returns provided default subject, if not in args.
|
376
|
-
# @param [Object] args
|
377
|
-
# @param [String] subject
|
378
|
-
# @return [Array]
|
379
|
-
def _scene_subject_with_opts(args, subject = '')
|
380
|
-
if args[0].is_a?(Hash)
|
381
|
-
[subject, args[0]]
|
382
|
-
else
|
383
|
-
[args[0] || subject, args[1] || {}]
|
384
|
-
end
|
385
|
-
end
|
386
373
|
end
|
387
374
|
end
|
388
375
|
end
|
@@ -27,6 +27,13 @@ module RubySmart
|
|
27
27
|
class_variable_set('@@scenes', scenes)
|
28
28
|
end
|
29
29
|
|
30
|
+
# returns true, if provided *key* is a registered scene option
|
31
|
+
# @param [Symbol] key
|
32
|
+
# @return [Boolean]
|
33
|
+
def scene?(key)
|
34
|
+
scenes.key?(key)
|
35
|
+
end
|
36
|
+
|
30
37
|
# registers a new scene by provided key & options
|
31
38
|
# also defines this method by provided block
|
32
39
|
#
|
@@ -64,11 +71,14 @@ module RubySmart
|
|
64
71
|
|
65
72
|
private
|
66
73
|
|
67
|
-
# resolves scene options by provided key & merges them with additional
|
74
|
+
# resolves scene options by provided key & merges them with additional *opts*
|
68
75
|
# @param [Symbol] key
|
69
76
|
# @param [Array<Hash>] opts
|
70
|
-
def
|
71
|
-
|
77
|
+
def _scene_opts(key, **opts)
|
78
|
+
{
|
79
|
+
**(scenes[key] || {}),
|
80
|
+
**opts
|
81
|
+
}
|
72
82
|
end
|
73
83
|
end
|
74
84
|
end
|
@@ -11,9 +11,8 @@ module RubySmart
|
|
11
11
|
# > ================================================= [Debug] ================================================
|
12
12
|
# > "DEBUGGED DATA" <- analyzed by awesome_print#ai method
|
13
13
|
# > ==========================================================================================================
|
14
|
-
base.scene :debug, { level: :debug, inspect: true, payload: [[:mask, ' [%{subject}] '], :__data__, :mask] } do |data,
|
15
|
-
|
16
|
-
self.log data, _scene_opt(:debug, { subject: subject }, opts)
|
14
|
+
base.scene :debug, { level: :debug, inspect: true, payload: [[:mask, ' [%{subject}] '], :__data__, :mask] } do |data, subject = 'Debug', **opts|
|
15
|
+
self.log data, _scene_opts(:debug, subject: subject.to_s, **opts)
|
17
16
|
end
|
18
17
|
|
19
18
|
# info method (BASE)
|
@@ -23,9 +22,8 @@ module RubySmart
|
|
23
22
|
# > ================================================= [Info] =================================================
|
24
23
|
# > DATA
|
25
24
|
# > ==========================================================================================================
|
26
|
-
base.scene :info, { level: :info, mask: { clr: :cyan }, payload: [[:mask, ' [%{subject}] '], :__data__, :mask] } do |data,
|
27
|
-
|
28
|
-
self.log data, _scene_opt(:info, { subject: subject }, opts)
|
25
|
+
base.scene :info, { level: :info, mask: { clr: :cyan }, payload: [[:mask, ' [%{subject}] '], :__data__, :mask] } do |data, subject = 'Info', **opts|
|
26
|
+
self.log data, _scene_opts(:info, subject: subject.to_s, **opts)
|
29
27
|
end
|
30
28
|
|
31
29
|
# warn method (BASE)
|
@@ -35,9 +33,8 @@ module RubySmart
|
|
35
33
|
# > ================================================= [Warn] =================================================
|
36
34
|
# > DATA
|
37
35
|
# > ==========================================================================================================
|
38
|
-
base.scene :warn, { level: :warn, mask: { clr: :yellow }, payload: [[:mask, ' [%{subject}] '], :__data__, :mask] } do |data,
|
39
|
-
|
40
|
-
self.log data, _scene_opt(:warn, { subject: subject }, opts)
|
36
|
+
base.scene :warn, { level: :warn, mask: { clr: :yellow }, payload: [[:mask, ' [%{subject}] '], :__data__, :mask] } do |data, subject = 'Warn', **opts|
|
37
|
+
self.log data, _scene_opts(:warn, subject: subject.to_s, **opts)
|
41
38
|
end
|
42
39
|
|
43
40
|
# error method (BASE)
|
@@ -47,9 +44,8 @@ module RubySmart
|
|
47
44
|
# > ================================================ [Error] =================================================
|
48
45
|
# > DATA
|
49
46
|
# > ==========================================================================================================
|
50
|
-
base.scene :error, { level: :error, mask: { clr: :red }, payload: [[:mask, ' [%{subject}] '], :__data__, :mask] } do |data,
|
51
|
-
|
52
|
-
self.log data, _scene_opt(:error, { subject: subject }, opts)
|
47
|
+
base.scene :error, { level: :error, mask: { clr: :red }, payload: [[:mask, ' [%{subject}] '], :__data__, :mask] } do |data, subject = 'Error', **opts|
|
48
|
+
self.log data, _scene_opts(:error, subject: subject.to_s, **opts)
|
53
49
|
end
|
54
50
|
|
55
51
|
# fatal method (BASE)
|
@@ -59,9 +55,8 @@ module RubySmart
|
|
59
55
|
# > ================================================ [Fatal] =================================================
|
60
56
|
# > DATA
|
61
57
|
# > ==========================================================================================================
|
62
|
-
base.scene :fatal, { level: :fatal, mask: { clr: :bg_red }, payload: [[:mask, ' [%{subject}] '], :__data__, :mask] } do |data,
|
63
|
-
|
64
|
-
self.log data, _scene_opt(:fatal, { subject: subject }, opts)
|
58
|
+
base.scene :fatal, { level: :fatal, mask: { clr: :bg_red }, payload: [[:mask, ' [%{subject}] '], :__data__, :mask] } do |data, subject = 'Fatal', **opts|
|
59
|
+
self.log data, _scene_opts(:fatal, subject: subject.to_s, **opts)
|
65
60
|
end
|
66
61
|
|
67
62
|
# unknown method (BASE)
|
@@ -71,9 +66,8 @@ module RubySmart
|
|
71
66
|
# > =============================================== [Unknown] ================================================
|
72
67
|
# > DATA
|
73
68
|
# > ==========================================================================================================
|
74
|
-
base.scene :unknown, { level: :unknown, mask: { clr: :gray }, payload: [[:mask, ' [%{subject}] '], :__data__, :mask] } do |data,
|
75
|
-
|
76
|
-
self.log data, _scene_opt(:unknown, { subject: subject }, opts)
|
69
|
+
base.scene :unknown, { level: :unknown, mask: { clr: :gray }, payload: [[:mask, ' [%{subject}] '], :__data__, :mask] } do |data, subject = 'Unknown', **opts|
|
70
|
+
self.log data, _scene_opts(:unknown, subject: subject.to_s, **opts)
|
77
71
|
end
|
78
72
|
|
79
73
|
# success method
|
@@ -83,9 +77,8 @@ module RubySmart
|
|
83
77
|
# > ================================================ [Success] ================================================
|
84
78
|
# > DATA
|
85
79
|
# > ===========================================================================================================
|
86
|
-
base.scene :success, { level: :success, mask: { clr: :green }, payload: [[:mask, ' [%{subject}] '], :__data__, :mask] } do |data,
|
87
|
-
|
88
|
-
self.log data, _scene_opt(:success, { subject: subject }, opts)
|
80
|
+
base.scene :success, { level: :success, mask: { clr: :green }, payload: [[:mask, ' [%{subject}] '], :__data__, :mask] } do |data, subject = 'Success', **opts|
|
81
|
+
self.log data, _scene_opts(:success, subject: subject.to_s, **opts)
|
89
82
|
end
|
90
83
|
|
91
84
|
# header method
|
@@ -95,11 +88,11 @@ module RubySmart
|
|
95
88
|
# > ===========================================================================================================
|
96
89
|
# > ================================================ <Subject> ================================================
|
97
90
|
# > ===========================================================================================================
|
98
|
-
base.scene :header, { level: :debug, payload: [:mask, [:mask, ' <%{subject}> '], :mask] } do |subject, opts
|
91
|
+
base.scene :header, { level: :debug, payload: [:mask, [:mask, ' <%{subject}> '], :mask] } do |subject, **opts|
|
99
92
|
# autostart a timer method, if required
|
100
93
|
self.timer(:start, :default) if opts[:timer]
|
101
94
|
|
102
|
-
self.log nil,
|
95
|
+
self.log nil, _scene_opts(:header, subject: subject.to_s, **opts)
|
103
96
|
end
|
104
97
|
|
105
98
|
# footer method
|
@@ -109,8 +102,8 @@ module RubySmart
|
|
109
102
|
# > ===========================================================================================================
|
110
103
|
# > ================================================ >Subject< ================================================
|
111
104
|
# > ===========================================================================================================
|
112
|
-
base.scene :footer, { level: :debug, payload: [:mask, [:mask, ' >%{subject}< '], :mask] } do |subject, opts
|
113
|
-
self.log nil,
|
105
|
+
base.scene :footer, { level: :debug, payload: [:mask, [:mask, ' >%{subject}< '], :mask] } do |subject, **opts|
|
106
|
+
self.log nil, _scene_opts(:footer, subject: subject.to_s, **opts)
|
114
107
|
|
115
108
|
# clears & prints timer
|
116
109
|
self.desc("duration: #{self.timer(:clear, :default, :humanized => true)}") if opts[:timer]
|
@@ -123,8 +116,8 @@ module RubySmart
|
|
123
116
|
# > --------------------------------------------------------------------------------
|
124
117
|
# > #----------------------------------- Subject ----------------------------------#
|
125
118
|
# > --------------------------------------------------------------------------------
|
126
|
-
base.scene :topic, { level: :debug, mask: { char: '-', length: 95, clr: :blueish }, payload: [:mask, [:mask, '%{title}'], :mask] } do |subject, opts
|
127
|
-
opts =
|
119
|
+
base.scene :topic, { level: :debug, mask: { char: '-', length: 95, clr: :blueish }, payload: [:mask, [:mask, '%{title}'], :mask] } do |subject, **opts|
|
120
|
+
opts = _scene_opts(:topic, **opts)
|
128
121
|
txt = " #{subject} ".center(opts[:mask][:length] - 2, opts[:mask][:char])
|
129
122
|
opts[:title] = "##{txt}#"
|
130
123
|
|
@@ -137,8 +130,8 @@ module RubySmart
|
|
137
130
|
#
|
138
131
|
# > # Subject
|
139
132
|
# > ----------------------------------------------------------------------
|
140
|
-
base.scene :theme, { level: :debug, clr: :purple, mask: { char: '-', length: 85, clr: :purple }, payload: [[:txt, '# %{subject}'], :mask] } do |subject, opts
|
141
|
-
self.log nil,
|
133
|
+
base.scene :theme, { level: :debug, clr: :purple, mask: { char: '-', length: 85, clr: :purple }, payload: [[:txt, '# %{subject}'], :mask] } do |subject, **opts|
|
134
|
+
self.log nil, _scene_opts(:theme, subject: subject.to_s, **opts)
|
142
135
|
end
|
143
136
|
|
144
137
|
# theme_result method
|
@@ -148,9 +141,9 @@ module RubySmart
|
|
148
141
|
# > ----------------------------------------------------------------------
|
149
142
|
# > -> Result
|
150
143
|
# >
|
151
|
-
base.scene :theme_result, { level: :debug, mask: { char: '-', length: 85, clr: :purple }, payload: [:mask, [:txt, '-> %{result}'], ''] } do |result, status = nil, opts
|
144
|
+
base.scene :theme_result, { level: :debug, mask: { char: '-', length: 85, clr: :purple }, payload: [:mask, [:txt, '-> %{result}'], ''] } do |result, status = nil, **opts|
|
152
145
|
res_or_clr = status.nil? ? result : status
|
153
|
-
self.log nil,
|
146
|
+
self.log nil, _scene_opts(:theme_result, result: result, clr: _res_clr(res_or_clr), **opts)
|
154
147
|
end
|
155
148
|
|
156
149
|
# theme_line method
|
@@ -158,8 +151,8 @@ module RubySmart
|
|
158
151
|
# prints: colored line with no text
|
159
152
|
#
|
160
153
|
# > ----------------------------------------------------------------------
|
161
|
-
base.scene :theme_line, { level: :debug, mask: { char: '-', length: 85, clr: :purple }, payload: [:mask] } do
|
162
|
-
self.log nil,
|
154
|
+
base.scene :theme_line, { level: :debug, mask: { char: '-', length: 85, clr: :purple }, payload: [:mask] } do |**opts|
|
155
|
+
self.log nil, _scene_opts(:theme_line, **opts)
|
163
156
|
end
|
164
157
|
|
165
158
|
# desc method
|
@@ -168,8 +161,8 @@ module RubySmart
|
|
168
161
|
#
|
169
162
|
# > "description"
|
170
163
|
# >
|
171
|
-
base.scene :desc, { level: :debug, clr: :purple, payload: [[:txt, '%{description}']] } do |description, opts
|
172
|
-
self.log nil,
|
164
|
+
base.scene :desc, { level: :debug, clr: :purple, payload: [[:txt, '%{description}']] } do |description, **opts|
|
165
|
+
self.log nil, _scene_opts(:desc, description: description.to_s, **opts)
|
173
166
|
end
|
174
167
|
|
175
168
|
# job method
|
@@ -179,8 +172,8 @@ module RubySmart
|
|
179
172
|
#
|
180
173
|
# > - Job name =>
|
181
174
|
# ________________________________________________________________ <- 64 chars
|
182
|
-
base.scene :job, { level: :debug, clr: :cyan, nl: false, length: 64, payload: [[:concat, ['- ', [:txt, '%{name}'], ' => ']]] } do |name, opts
|
183
|
-
self.log nil,
|
175
|
+
base.scene :job, { level: :debug, clr: :cyan, nl: false, length: 64, payload: [[:concat, ['- ', [:txt, '%{name}'], ' => ']]] } do |name, **opts, &block|
|
176
|
+
self.log nil, _scene_opts(:job, name: name, **opts)
|
184
177
|
self.result(*block.call) if block_given?
|
185
178
|
end
|
186
179
|
|
@@ -191,8 +184,8 @@ module RubySmart
|
|
191
184
|
#
|
192
185
|
# > * Subjob name =>
|
193
186
|
# ______________________________________________________________ <- 62 chars
|
194
|
-
base.scene :sub_job, { level: :debug, clr: :cyan, nl: false, length: 62, payload: [[:concat, [' * ', [:txt, '%{name}'], ' => ']]] } do |name, opts
|
195
|
-
self.log nil,
|
187
|
+
base.scene :sub_job, { level: :debug, clr: :cyan, nl: false, length: 62, payload: [[:concat, [' * ', [:txt, '%{name}'], ' => ']]] } do |name, **opts, &block|
|
188
|
+
self.log nil, _scene_opts(:sub_job, name: name, **opts)
|
196
189
|
self.result(*block.call) if block_given?
|
197
190
|
end
|
198
191
|
|
@@ -201,9 +194,9 @@ module RubySmart
|
|
201
194
|
# prints: colored result
|
202
195
|
#
|
203
196
|
# > Result
|
204
|
-
base.scene :result, { level: :debug, payload: [[:txt, '%{result}']] } do |result, status = nil, opts
|
197
|
+
base.scene :result, { level: :debug, payload: [[:txt, '%{result}']] } do |result, status = nil, **opts|
|
205
198
|
res_or_clr = status.nil? ? result : status
|
206
|
-
self.log nil,
|
199
|
+
self.log nil, _scene_opts(:result, result: result, clr: _res_clr(res_or_clr), **opts)
|
207
200
|
end
|
208
201
|
|
209
202
|
# job_result method
|
@@ -211,9 +204,9 @@ module RubySmart
|
|
211
204
|
# prints: job with combined colored result
|
212
205
|
#
|
213
206
|
# > - Job name => Result
|
214
|
-
base.scene :job_result, { level: :debug } do |name, result, status = nil, opts
|
215
|
-
self.job(name, opts)
|
216
|
-
self.result(result, status, opts)
|
207
|
+
base.scene :job_result, { level: :debug } do |name, result, status = nil, **opts|
|
208
|
+
self.job(name, **opts)
|
209
|
+
self.result(result, status, **opts)
|
217
210
|
end
|
218
211
|
|
219
212
|
# sub_job_result method
|
@@ -221,9 +214,9 @@ module RubySmart
|
|
221
214
|
# prints: sub_job with combined colored result
|
222
215
|
#
|
223
216
|
# > * Subjob name => Result
|
224
|
-
base.scene :sub_job_result, { level: :debug } do |name, result, status = nil, opts
|
225
|
-
self.sub_job(name, opts)
|
226
|
-
self.result(result, status, opts)
|
217
|
+
base.scene :sub_job_result, { level: :debug } do |name, result, status = nil, **opts|
|
218
|
+
self.sub_job(name, **opts)
|
219
|
+
self.result(result, status, **opts)
|
227
220
|
end
|
228
221
|
|
229
222
|
# line method
|
@@ -231,8 +224,8 @@ module RubySmart
|
|
231
224
|
# prints: just a line with data
|
232
225
|
#
|
233
226
|
# > DATA
|
234
|
-
base.scene :line, { level: :debug } do |data, opts
|
235
|
-
self.log data,
|
227
|
+
base.scene :line, { level: :debug } do |data, **opts|
|
228
|
+
self.log data, _scene_opts(:line, **opts)
|
236
229
|
end
|
237
230
|
|
238
231
|
# print method
|
@@ -240,8 +233,8 @@ module RubySmart
|
|
240
233
|
# prints: prints data without a newline
|
241
234
|
#
|
242
235
|
# > DATA
|
243
|
-
base.scene :print, { level: :debug, nl: false } do |data, opts
|
244
|
-
self.log data,
|
236
|
+
base.scene :print, { level: :debug, nl: false } do |data, **opts|
|
237
|
+
self.log data, _scene_opts(:print, **opts)
|
245
238
|
end
|
246
239
|
|
247
240
|
# nl method
|
@@ -250,8 +243,8 @@ module RubySmart
|
|
250
243
|
#
|
251
244
|
# >
|
252
245
|
# >
|
253
|
-
base.scene :nl, { level: :debug } do
|
254
|
-
self.log '',
|
246
|
+
base.scene :nl, { level: :debug } do |**opts|
|
247
|
+
self.log '', _scene_opts(:nl, **opts)
|
255
248
|
end
|
256
249
|
|
257
250
|
# spec method
|
@@ -263,7 +256,7 @@ module RubySmart
|
|
263
256
|
# "other" => ? (yellow)
|
264
257
|
#
|
265
258
|
# > .FFF...??...F....F...F..???....F...??
|
266
|
-
base.scene :spec, { level: :debug, nl: false, payload: [[:txt, '%{result}']] } do |status, opts
|
259
|
+
base.scene :spec, { level: :debug, nl: false, payload: [[:txt, '%{result}']] } do |status, **opts|
|
267
260
|
result = if status.is_a?(TrueClass)
|
268
261
|
'.'
|
269
262
|
elsif status.is_a?(FalseClass)
|
@@ -272,7 +265,7 @@ module RubySmart
|
|
272
265
|
status = :yellow
|
273
266
|
'?'
|
274
267
|
end
|
275
|
-
self.log nil,
|
268
|
+
self.log nil, _scene_opts(:spec, result: result, clr: _res_clr(status), **opts)
|
276
269
|
end
|
277
270
|
|
278
271
|
# progress method
|
@@ -283,7 +276,7 @@ module RubySmart
|
|
283
276
|
# > - Progress of Step 1 [ 40%] ===================>------------------------------
|
284
277
|
# ________________________________________________ <- 48 chars
|
285
278
|
# 50 chars -> __________________________________________________
|
286
|
-
base.scene :progress, { level: :debug, payload: [[:txt, '- %{name} [%{perc}%] %{progress}']] } do |name, perc, opts
|
279
|
+
base.scene :progress, { level: :debug, payload: [[:txt, '- %{name} [%{perc}%] %{progress}']] } do |name, perc, **opts|
|
287
280
|
pmask_length = 50
|
288
281
|
|
289
282
|
# convert and fix progress
|
@@ -298,7 +291,7 @@ module RubySmart
|
|
298
291
|
|
299
292
|
progress_string = _clr(('=' * pmask_left_length) + '>', :green) + _clr('-' * pmask_right_length, :red)
|
300
293
|
perc_string = perc.to_s.rjust(3, ' ')
|
301
|
-
self.log nil,
|
294
|
+
self.log nil, _scene_opts(:progress, name: _clr(_lgth(name, 48), :cyan), perc: perc_string, progress: progress_string, **opts)
|
302
295
|
end
|
303
296
|
|
304
297
|
# processed method
|
@@ -309,7 +302,7 @@ module RubySmart
|
|
309
302
|
# ╟ doing some cool log
|
310
303
|
# ╟ doing some extra log
|
311
304
|
# ╚ END ❯ job [SUCCESS] (duration: 4.34223)
|
312
|
-
base.scene :processed, { level: :debug } do |name, opts
|
305
|
+
base.scene :processed, { level: :debug } do |name, **opts, &block|
|
313
306
|
# increase level
|
314
307
|
lvl = processed_lvl(:up)
|
315
308
|
|
@@ -326,7 +319,7 @@ module RubySmart
|
|
326
319
|
self.timer(:start, timer_key)
|
327
320
|
|
328
321
|
# send START name as +data+ - the full log line is created through the +_pcd+ method.
|
329
|
-
self.log(name,
|
322
|
+
self.log(name, _scene_opts(:processed, **opts, pcd: :start))
|
330
323
|
|
331
324
|
# run the provided block and resolve result
|
332
325
|
result_str = case block.call
|
@@ -345,7 +338,7 @@ module RubySmart
|
|
345
338
|
result_str ||= ''
|
346
339
|
|
347
340
|
# send END name with result & possible time as +data+ - the full log line is created through the +_pcd+ method.
|
348
|
-
self.log("#{name} #{result_str}#{(timer_key ? "(#{self.timer(:clear, timer_key, humanized: true)})" : '')}",
|
341
|
+
self.log("#{name} #{result_str}#{(timer_key ? "(#{self.timer(:clear, timer_key, humanized: true)})" : '')}", _scene_opts(:processed, **opts, pcd: :end ))
|
349
342
|
|
350
343
|
# reduce level
|
351
344
|
processed_lvl(:down)
|
@@ -357,26 +350,27 @@ module RubySmart
|
|
357
350
|
# model method
|
358
351
|
# log level @ error/success/info
|
359
352
|
# prints: ActiveRecord::Base related data, depending on the models "save" state (also shows possible errors)
|
360
|
-
base.scene :model do |model,
|
353
|
+
base.scene :model do |model, status = nil, **opts|
|
361
354
|
# build model-logging string
|
362
355
|
mdl_string = "#{model.id.present? ? "##{model.id} - " : ''}#{model.to_s[0..49]}"
|
363
356
|
|
364
357
|
# resolve model's status
|
365
|
-
status
|
358
|
+
status = ((model.persisted? && model.errors.empty?) ? (model.previous_changes.blank? ? :skipped : :success) : :error) if status.nil?
|
366
359
|
|
367
360
|
# switch between status
|
368
361
|
case status
|
369
362
|
when :success
|
370
363
|
# show verbose logging for updated records
|
371
364
|
if opts[:verbose] != false && !model.previously_new_record?
|
372
|
-
|
365
|
+
self.success("#{mdl_string} (#{model.previous_changes.inspect})", tag: "#{model.class.name.upcase}|UPDATED", **opts)
|
373
366
|
else
|
374
|
-
|
367
|
+
self.success(mdl_string, tag: "#{model.class.name.upcase}|#{(model.previously_new_record? ? 'CREATED' : 'UPDATED')}", **opts)
|
375
368
|
end
|
376
369
|
when :error
|
377
|
-
|
370
|
+
msg_string = model.errors.full_messages.join(', ')
|
371
|
+
self.error("#{mdl_string} (#{msg_string.present? ? msg_string : '-'})", tag: "#{model.class.name.upcase}|ERROR", **opts)
|
378
372
|
else
|
379
|
-
|
373
|
+
self.info(mdl_string, tag: "#{model.class.name.upcase}|#{status}", **opts)
|
380
374
|
end
|
381
375
|
end
|
382
376
|
end
|
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.
|
4
|
+
version: 1.5.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: 2024-
|
11
|
+
date: 2024-09-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby_smart-support
|