ruby_smart-simple_logger 1.2.2 → 1.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/ruby.yml +11 -15
- data/README.md +7 -7
- data/docs/CHANGELOG.md +14 -0
- data/lib/ruby_smart/simple_logger/extensions/helper.rb +42 -12
- data/lib/ruby_smart/simple_logger/extensions/processed.rb +48 -12
- data/lib/ruby_smart/simple_logger/extensions/simple_log.rb +34 -6
- data/lib/ruby_smart/simple_logger/extensions/timer.rb +9 -7
- data/lib/ruby_smart/simple_logger/formatter.rb +2 -2
- data/lib/ruby_smart/simple_logger/gem_version.rb +2 -2
- data/lib/ruby_smart/simple_logger/scenes.rb +63 -27
- data/ruby_smart-simple_logger.gemspec +2 -0
- metadata +34 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 101c7a9ab2862c9ff3e7ace74f812a20a522dfa7fa8c6fcdf9f9accc53fd29e2
|
4
|
+
data.tar.gz: 1e1f7d6e1c9cbfe48a21cc8cceaa7cd37de7712363ae78e80bcff87aa6c5ca5a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 875fc9ea64929088e6a445f43b1e3a0c7b1c92de106a53c8112c68a3eb28ab5ea081c2a1e21d7d672d7e3109c68e68a83283be41364d65b2c450b6932408e15a
|
7
|
+
data.tar.gz: 9be8b0019a5afb3b3a9050dcb6139d9cf2ffe9fbd89549ebb717e8e4a2b59ee981dad95948400836a78e8b8205a324dbd2a35dea6638567143e37cbc93425e32
|
data/.github/workflows/ruby.yml
CHANGED
@@ -18,21 +18,17 @@ permissions:
|
|
18
18
|
|
19
19
|
jobs:
|
20
20
|
test:
|
21
|
-
|
22
|
-
runs-on: ubuntu-latest
|
23
21
|
strategy:
|
22
|
+
fail-fast: false
|
24
23
|
matrix:
|
25
|
-
|
26
|
-
|
24
|
+
os: [ubuntu-latest]
|
25
|
+
# Due to https://github.com/actions/runner/issues/849, we have to use quotes for '3.0'
|
26
|
+
ruby: ['3.2', '3.1', '3.0', '2.7', '2.6']
|
27
|
+
runs-on: ${{ matrix.os }}
|
27
28
|
steps:
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
with:
|
35
|
-
ruby-version: ${{ matrix.ruby-version }}
|
36
|
-
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
37
|
-
- name: Run tests
|
38
|
-
run: bundle exec rake
|
29
|
+
- uses: actions/checkout@v3
|
30
|
+
- uses: ruby/setup-ruby@v1
|
31
|
+
with:
|
32
|
+
ruby-version: ${{ matrix.ruby }}
|
33
|
+
bundler-cache: true # runs 'bundle install' and caches installed gems automatically
|
34
|
+
- run: bundle exec rake
|
data/README.md
CHANGED
@@ -560,7 +560,7 @@ The following PRE-defined scenes are available. _(You can define your own scenes
|
|
560
560
|
# > ==========================================================================================================
|
561
561
|
```
|
562
562
|
|
563
|
-
### info, warn, error, fatal, success (data, subject = 'name')
|
563
|
+
### info, warn, error, fatal, unknown, success (data, subject = 'name')
|
564
564
|
```ruby
|
565
565
|
# info method (BASE)
|
566
566
|
# severity: methods name
|
@@ -748,19 +748,19 @@ l.processed("Process Alpha", timer: true) do
|
|
748
748
|
end
|
749
749
|
|
750
750
|
|
751
|
-
# ╔ START
|
751
|
+
# ╔ START ❯ Process Alpha
|
752
752
|
# ╟ find files
|
753
753
|
# ╟ found 34 files
|
754
|
-
# ║ ┌ START
|
754
|
+
# ║ ┌ START ❯ extracting ...
|
755
755
|
# ║ ├ 10% done
|
756
756
|
# ║ ├ 20% done
|
757
757
|
# ║ ├ 100% done
|
758
|
-
# ║ └
|
759
|
-
# ║ ┌ START
|
758
|
+
# ║ └ END ❯ extracting ... [SUCCESS] (0.000244804)
|
759
|
+
# ║ ┌ START ❯ transforming ...
|
760
760
|
# ║ ├ bad memory
|
761
761
|
# ║ ├ rolling back
|
762
|
-
# ║ └
|
763
|
-
# ╚
|
762
|
+
# ║ └ END ❯ transforming ... [FAIL]
|
763
|
+
# ╚ END ❯ Process Alpha (0.001036969)
|
764
764
|
```
|
765
765
|
|
766
766
|
### _other useful methods_
|
data/docs/CHANGELOG.md
CHANGED
@@ -1,5 +1,19 @@
|
|
1
1
|
# RubySmart::SimpleLogger - CHANGELOG
|
2
2
|
|
3
|
+
## [1.3.0] - 2023-08-15
|
4
|
+
* **[add]** exception message within `processed`-scene
|
5
|
+
* **[add]** new logging option `tag`, to prefix a log-string with a [TAG]
|
6
|
+
* **[add]** logger options `processed: false` & `tagged: false` to prevent processing or tagging
|
7
|
+
* **[add]** `_tagged`-helper method
|
8
|
+
* **[add]** `__scene_subject_with_opts`-helper method to grep subject&opts from args (used for default severities)
|
9
|
+
* **[add]** additional box_chars for 'tagged' & 'feed' extensions - used @ `processed`-scene
|
10
|
+
* **[add]** `unknown`-scene
|
11
|
+
* **[ref]** `processed`-scene with better logging chars & homogenous syntax for humanized reading
|
12
|
+
* **[fix]** missing '_declr' for memory formatting (only on Strings)
|
13
|
+
* **[fix]** missing 'clr:false' option for memory devices
|
14
|
+
* **[fix]** exception while in `processed`-scene not logging the END-line
|
15
|
+
* **[fix]** re-using timer-methods with the same key, did not restart the 'total' measurement
|
16
|
+
|
3
17
|
## [1.2.2] - 2023-03-15
|
4
18
|
* **[ref]** simplify device-generation for builtins
|
5
19
|
* **[fix]** `ActionView::Helpers::DateHelper` require, which breaks rails loading process in some cases
|
@@ -14,8 +14,7 @@ module RubySmart
|
|
14
14
|
# set / overwrite default opts
|
15
15
|
# @param [Hash] opts
|
16
16
|
def _opts_init!(opts)
|
17
|
-
|
18
|
-
# level
|
17
|
+
# -- level ---------------------------------------------------------------------------------------------------
|
19
18
|
|
20
19
|
# initialize a default rails-dependent output
|
21
20
|
if ::ThreadInfo.rails?
|
@@ -25,8 +24,7 @@ module RubySmart
|
|
25
24
|
# clean & rewrite level (possible symbols) to real level
|
26
25
|
opts[:level] = _level(opts[:level] || :debug)
|
27
26
|
|
28
|
-
|
29
|
-
# mask
|
27
|
+
# -- mask ----------------------------------------------------------------------------------------------------
|
30
28
|
|
31
29
|
# set mask from options
|
32
30
|
self.mask(opts[:mask]) if opts[:mask]
|
@@ -39,13 +37,18 @@ module RubySmart
|
|
39
37
|
self.mask(length: ::ThreadInfo.winsize[1])
|
40
38
|
end
|
41
39
|
|
42
|
-
|
43
|
-
# instance related
|
40
|
+
# -- instance related ----------------------------------------------------------------------------------------
|
44
41
|
|
45
42
|
# ignore payload and send data directly to the logdev
|
46
|
-
@ignore_payload
|
43
|
+
@ignore_payload = true if @ignore_payload.nil? && opts[:payload] == false
|
47
44
|
|
48
|
-
#
|
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)
|
49
52
|
# 'disable' inspector, if false was provided - which simply results in +#to_s+
|
50
53
|
@inspector = (opts[:inspect] == false) ? :to_s : opts[:inspector]
|
51
54
|
|
@@ -113,7 +116,7 @@ module RubySmart
|
|
113
116
|
opts[:format] ||= :plain
|
114
117
|
|
115
118
|
# fix nl - which depends on other opts
|
116
|
-
opts[:nl]
|
119
|
+
opts[:nl] = _nl(opts)
|
117
120
|
|
118
121
|
# fix clr
|
119
122
|
opts[:clr] = true if opts[:clr].nil?
|
@@ -152,14 +155,16 @@ module RubySmart
|
|
152
155
|
when :proc
|
153
156
|
# force overwrite opts
|
154
157
|
@ignore_payload = true
|
155
|
-
opts[:nl]
|
156
|
-
opts[:format]
|
158
|
+
opts[:nl] = false
|
159
|
+
opts[:format] = :passthrough
|
157
160
|
|
158
161
|
::RubySmart::SimpleLogger::Devices::ProcDevice.new(opts.delete(:proc))
|
159
162
|
when :memory
|
160
163
|
# force overwrite opts
|
161
164
|
@ignore_payload = true
|
162
|
-
opts[:format]
|
165
|
+
opts[:format] = :memory
|
166
|
+
# no color logging for memory devices
|
167
|
+
opts[:clr] = false
|
163
168
|
|
164
169
|
::RubySmart::SimpleLogger::Devices::MemoryDevice.new
|
165
170
|
when Module, String
|
@@ -275,6 +280,18 @@ module RubySmart
|
|
275
280
|
end
|
276
281
|
end
|
277
282
|
|
283
|
+
# 'tags' a provided string
|
284
|
+
# returns the string if no tag was provided or general tags are disabled
|
285
|
+
# @param [String] str
|
286
|
+
# @param [nil|Symbol|String] tag
|
287
|
+
# @return [String]
|
288
|
+
def _tagged(str, tag = nil)
|
289
|
+
# check for active tag
|
290
|
+
return str if tag.nil? || ignore_tagged?
|
291
|
+
|
292
|
+
"#{"[#{tag.to_s.upcase.bg_cyan}]"} #{str}"
|
293
|
+
end
|
294
|
+
|
278
295
|
# colorizes a provided string
|
279
296
|
# returns the string if no color was provided or invalid
|
280
297
|
#
|
@@ -343,6 +360,19 @@ module RubySmart
|
|
343
360
|
res_or_clr.to_sym
|
344
361
|
end
|
345
362
|
end
|
363
|
+
|
364
|
+
# resolves subject & opts from provided args.
|
365
|
+
# returns provided default subject, if not in args.
|
366
|
+
# @param [Object] args
|
367
|
+
# @param [String] subject
|
368
|
+
# @return [Array]
|
369
|
+
def _scene_subject_with_opts(args, subject = '')
|
370
|
+
if args[0].is_a?(Hash)
|
371
|
+
[subject, args[0]]
|
372
|
+
else
|
373
|
+
[args[0] || subject, args[1] || {}]
|
374
|
+
end
|
375
|
+
end
|
346
376
|
end
|
347
377
|
end
|
348
378
|
end
|
@@ -12,10 +12,15 @@ module RubySmart
|
|
12
12
|
base.class_eval do
|
13
13
|
# set default box chars
|
14
14
|
self.box_chars = {
|
15
|
-
|
16
|
-
|
15
|
+
# control characters by provided +:pcd+
|
16
|
+
default: %w(╟ ├),
|
17
17
|
start: %w(╔ ┌),
|
18
|
-
end: %w(╚ └)
|
18
|
+
end: %w(╚ └),
|
19
|
+
|
20
|
+
# additional characters, added ad specific position
|
21
|
+
__processed__: %w(║ │),
|
22
|
+
__feed__: %w(═ ─),
|
23
|
+
__tagged__: %w(┄ ┄),
|
19
24
|
}.freeze
|
20
25
|
end
|
21
26
|
end
|
@@ -33,18 +38,20 @@ module RubySmart
|
|
33
38
|
module InstanceMethods
|
34
39
|
# returns the current processed level.
|
35
40
|
# by providing a handle it will either increase or decrease the current level.
|
36
|
-
# @param [
|
41
|
+
# @param [Symbol|Integer] handle - optional handle to increase or decrease the current lvl (+:up+ / +:down+)
|
37
42
|
# @return [Integer]
|
38
43
|
def processed_lvl(handle = nil)
|
39
44
|
@processed_lvl ||= -1
|
40
45
|
|
41
46
|
case handle
|
47
|
+
when :reset
|
48
|
+
@processed_lvl = -1
|
42
49
|
when :up
|
43
50
|
@processed_lvl += 1
|
44
51
|
when :down
|
45
52
|
@processed_lvl -= 1 if @processed_lvl >= 0
|
46
53
|
else
|
47
|
-
|
54
|
+
@processed_lvl = handle if handle.is_a?(Integer)
|
48
55
|
end
|
49
56
|
|
50
57
|
@processed_lvl
|
@@ -53,25 +60,54 @@ module RubySmart
|
|
53
60
|
# returns true if the processed state is active.
|
54
61
|
# @return [Boolean]
|
55
62
|
def processed?
|
56
|
-
processed_lvl >= 0
|
63
|
+
processed_lvl >= 0 && !@ignore_processed
|
57
64
|
end
|
58
65
|
|
59
66
|
private
|
60
67
|
|
61
68
|
# transforms the provided data into a 'processed' string and forces the data to be transformed to string.
|
62
69
|
# simple returns the provided data, if currently not processed.
|
63
|
-
# @param [
|
70
|
+
# @param [String] data
|
64
71
|
# @param [Hash] opts
|
65
|
-
# @return [
|
72
|
+
# @return [String]
|
66
73
|
def _pcd(data, opts)
|
67
74
|
# check for active pcd (processed)
|
68
75
|
return data if opts[:pcd] == false || !processed?
|
69
76
|
|
70
|
-
# resolve
|
77
|
+
# resolve the current level - either directly through the options or the +processed_lvl+.
|
71
78
|
lvl = opts[:lvl] || processed_lvl
|
72
79
|
|
73
|
-
#
|
74
|
-
|
80
|
+
# prepares the out-string array
|
81
|
+
strs = []
|
82
|
+
|
83
|
+
# add level-charters with indent
|
84
|
+
lvl.times.each { |i|
|
85
|
+
# ║ │
|
86
|
+
strs << _pcd_box_char(:__processed__, i) + ' '
|
87
|
+
}
|
88
|
+
|
89
|
+
# add pcd-related control character
|
90
|
+
strs << _pcd_box_char(opts[:pcd], lvl)
|
91
|
+
|
92
|
+
# add pcd-operation string
|
93
|
+
if opts[:pcd].is_a?(Symbol)
|
94
|
+
# ╔ START ❯
|
95
|
+
# └ END ❯
|
96
|
+
strs << " #{opts[:pcd].to_s.upcase.rjust(5)} \u276F"
|
97
|
+
end
|
98
|
+
|
99
|
+
# check for tagged
|
100
|
+
# ┄
|
101
|
+
if opts[:tag]
|
102
|
+
strs << _pcd_box_char(:__tagged__, lvl)
|
103
|
+
else
|
104
|
+
strs << ' '
|
105
|
+
end
|
106
|
+
|
107
|
+
# add data
|
108
|
+
strs << data.to_s
|
109
|
+
|
110
|
+
strs.join
|
75
111
|
end
|
76
112
|
|
77
113
|
# returns the processed box character for provided key and position.
|
@@ -81,7 +117,7 @@ module RubySmart
|
|
81
117
|
# @param [Integer] pos
|
82
118
|
# @return [String]
|
83
119
|
def _pcd_box_char(key, pos = 0)
|
84
|
-
chars = self.class.box_chars[key] || self.class.box_chars[:
|
120
|
+
chars = self.class.box_chars[key] || self.class.box_chars[:default]
|
85
121
|
chars[pos] || chars[-1]
|
86
122
|
end
|
87
123
|
end
|
@@ -53,7 +53,7 @@ module RubySmart
|
|
53
53
|
# prevent logging nil data
|
54
54
|
return false if data.nil?
|
55
55
|
|
56
|
-
add level,
|
56
|
+
add level, _parse_data(data, opts)
|
57
57
|
return true
|
58
58
|
end
|
59
59
|
|
@@ -82,6 +82,14 @@ module RubySmart
|
|
82
82
|
!!@ignore_payload
|
83
83
|
end
|
84
84
|
|
85
|
+
# returns true if no tags should be created - instead the data will be send directly to the logdev
|
86
|
+
# forces the *simple_log* method to prevent building tags from opts
|
87
|
+
#
|
88
|
+
# @return [Boolean]
|
89
|
+
def ignore_tagged?
|
90
|
+
!!@ignore_tagged
|
91
|
+
end
|
92
|
+
|
85
93
|
# resolve an inspector method for data inspection
|
86
94
|
# @return [Symbol, nil]
|
87
95
|
def inspector
|
@@ -107,7 +115,7 @@ module RubySmart
|
|
107
115
|
str = ''
|
108
116
|
if payload == self.class::PAYLOAD_DATA_KEY
|
109
117
|
# checks, if we should inspect the data
|
110
|
-
str <<
|
118
|
+
str << _parse_inspect_data(data, opts)
|
111
119
|
else
|
112
120
|
str << _parse_payload(payload, opts)
|
113
121
|
end
|
@@ -121,13 +129,33 @@ module RubySmart
|
|
121
129
|
true
|
122
130
|
end
|
123
131
|
|
124
|
-
#
|
132
|
+
# parses the provided data to string.
|
133
|
+
# - calls an inspection method, if provided
|
134
|
+
# - tags the string, if provided
|
135
|
+
# - adds processed prefix-chars, if provided
|
125
136
|
#
|
126
137
|
# @param [Object] data
|
127
|
-
# @param [
|
138
|
+
# @param [Hash] opts
|
139
|
+
# @return [String] stringified data
|
140
|
+
def _parse_data(data, opts)
|
141
|
+
_pcd(
|
142
|
+
_tagged(
|
143
|
+
data.to_s,
|
144
|
+
opts[:tag]
|
145
|
+
),
|
146
|
+
opts
|
147
|
+
)
|
148
|
+
end
|
149
|
+
|
150
|
+
# parses the provided data to string, but calls a possible inspect method.
|
151
|
+
# @param [Object] data
|
152
|
+
# @param [Hash] opts
|
128
153
|
# @return [String] stringified data
|
129
|
-
def
|
130
|
-
(
|
154
|
+
def _parse_inspect_data(data, opts)
|
155
|
+
_parse_data(
|
156
|
+
data.send(opts[:inspect] ? (opts[:inspector] || self.inspector) : :to_s),
|
157
|
+
opts
|
158
|
+
)
|
131
159
|
end
|
132
160
|
|
133
161
|
# parses a single payload with provided options
|
@@ -5,21 +5,23 @@ module RubySmart
|
|
5
5
|
module Extensions
|
6
6
|
module Timer
|
7
7
|
def timer(action, key = :default, opts = {})
|
8
|
+
return if key.nil?
|
9
|
+
|
8
10
|
@timers ||= {}
|
9
11
|
@timers[key] ||= {
|
10
12
|
start: nil,
|
11
13
|
stop: nil,
|
12
|
-
|
14
|
+
total: 0
|
13
15
|
}
|
14
16
|
|
15
17
|
case action
|
16
|
-
when :restart
|
18
|
+
when :start, :restart
|
17
19
|
@timers[key][:start] = Time.now
|
18
20
|
@timers[key][:stop] = nil
|
19
|
-
@timers[key][:
|
21
|
+
@timers[key][:total] = 0
|
20
22
|
|
21
23
|
true
|
22
|
-
when :
|
24
|
+
when :continue
|
23
25
|
@timers[key][:start] = Time.now
|
24
26
|
@timers[key][:stop] = nil
|
25
27
|
|
@@ -27,13 +29,13 @@ module RubySmart
|
|
27
29
|
when :stop
|
28
30
|
return false if !@timers[key][:start] || @timers[key][:stop]
|
29
31
|
@timers[key][:stop] = Time.now
|
30
|
-
@timers[key][:
|
32
|
+
@timers[key][:total] += @timers[key][:stop] - @timers[key][:start]
|
31
33
|
|
32
34
|
true
|
33
35
|
when :pause
|
34
36
|
return false if !@timers[key][:start] || @timers[key][:stop]
|
35
37
|
|
36
|
-
@timers[key][:
|
38
|
+
@timers[key][:total] += Time.now - @timers[key][:start]
|
37
39
|
@timers[key][:start] = nil
|
38
40
|
@timers[key][:stop] = nil
|
39
41
|
|
@@ -50,7 +52,7 @@ module RubySmart
|
|
50
52
|
current
|
51
53
|
end
|
52
54
|
when :current
|
53
|
-
current = @timers[key][:
|
55
|
+
current = @timers[key][:total]
|
54
56
|
current += Time.now - @timers[key][:start] if @timers[key][:start] && @timers[key][:stop].nil?
|
55
57
|
current
|
56
58
|
else
|
@@ -33,7 +33,7 @@ module RubySmart
|
|
33
33
|
plain: -> (_severity, _time, _progname, data) { _nl _declr(data.to_s) },
|
34
34
|
|
35
35
|
# specialized array for memory-logging
|
36
|
-
memory: -> (severity, time, _progname, data) { [severity.downcase.to_sym, time, data] },
|
36
|
+
memory: -> (severity, time, _progname, data) { [severity.downcase.to_sym, time, _declr(data)] },
|
37
37
|
|
38
38
|
# specialized string as datalog with every provided data in additional brackets -> [data] [data] [data]
|
39
39
|
datalog: -> (severity, time, _progname, data) {
|
@@ -202,7 +202,7 @@ module RubySmart
|
|
202
202
|
# @param [String] str
|
203
203
|
# @return [String]
|
204
204
|
def _declr(str)
|
205
|
-
if opts[:clr]
|
205
|
+
if opts[:clr] || !str.is_a?(String)
|
206
206
|
str
|
207
207
|
else
|
208
208
|
str.gsub(/\e\[[\d;]+m/, '')
|
@@ -11,7 +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,
|
14
|
+
base.scene :debug, { level: :debug, inspect: true, payload: [[:mask, ' [%{subject}] '], :__data__, :mask] } do |data, *args|
|
15
|
+
subject, opts = _scene_subject_with_opts(args, 'Debug')
|
15
16
|
self.log data, _scene_opt(:debug, { subject: subject }, opts)
|
16
17
|
end
|
17
18
|
|
@@ -22,7 +23,8 @@ module RubySmart
|
|
22
23
|
# > ================================================= [Info] =================================================
|
23
24
|
# > DATA
|
24
25
|
# > ==========================================================================================================
|
25
|
-
base.scene :info, { level: :info, mask: { clr: :cyan }, payload: [[:mask, ' [%{subject}] '], :__data__, :mask] } do |data,
|
26
|
+
base.scene :info, { level: :info, mask: { clr: :cyan }, payload: [[:mask, ' [%{subject}] '], :__data__, :mask] } do |data, *args|
|
27
|
+
subject, opts = _scene_subject_with_opts(args, 'Info')
|
26
28
|
self.log data, _scene_opt(:info, { subject: subject }, opts)
|
27
29
|
end
|
28
30
|
|
@@ -33,7 +35,8 @@ module RubySmart
|
|
33
35
|
# > ================================================= [Warn] =================================================
|
34
36
|
# > DATA
|
35
37
|
# > ==========================================================================================================
|
36
|
-
base.scene :warn, { level: :warn, mask: { clr: :yellow }, payload: [[:mask, ' [%{subject}] '], :__data__, :mask] } do |data,
|
38
|
+
base.scene :warn, { level: :warn, mask: { clr: :yellow }, payload: [[:mask, ' [%{subject}] '], :__data__, :mask] } do |data, *args|
|
39
|
+
subject, opts = _scene_subject_with_opts(args, 'Warn')
|
37
40
|
self.log data, _scene_opt(:warn, { subject: subject }, opts)
|
38
41
|
end
|
39
42
|
|
@@ -44,7 +47,8 @@ module RubySmart
|
|
44
47
|
# > ================================================ [Error] =================================================
|
45
48
|
# > DATA
|
46
49
|
# > ==========================================================================================================
|
47
|
-
base.scene :error, { level: :error, mask: { clr: :red }, payload: [[:mask, ' [%{subject}] '], :__data__, :mask] } do |data
|
50
|
+
base.scene :error, { level: :error, mask: { clr: :red }, payload: [[:mask, ' [%{subject}] '], :__data__, :mask] } do |data,*args|
|
51
|
+
subject, opts = _scene_subject_with_opts(args, 'Error')
|
48
52
|
self.log data, _scene_opt(:error, { subject: subject }, opts)
|
49
53
|
end
|
50
54
|
|
@@ -55,10 +59,23 @@ module RubySmart
|
|
55
59
|
# > ================================================ [Fatal] =================================================
|
56
60
|
# > DATA
|
57
61
|
# > ==========================================================================================================
|
58
|
-
base.scene :fatal, { level: :fatal, mask: { clr: :bg_red }, payload: [[:mask, ' [%{subject}] '], :__data__, :mask] } do |data,
|
62
|
+
base.scene :fatal, { level: :fatal, mask: { clr: :bg_red }, payload: [[:mask, ' [%{subject}] '], :__data__, :mask] } do |data, *args|
|
63
|
+
subject, opts = _scene_subject_with_opts(args, 'Fatal')
|
59
64
|
self.log data, _scene_opt(:fatal, { subject: subject }, opts)
|
60
65
|
end
|
61
66
|
|
67
|
+
# unknown method (BASE)
|
68
|
+
# log level @ unknown
|
69
|
+
# prints: enclosed data
|
70
|
+
#
|
71
|
+
# > =============================================== [Unknown] ================================================
|
72
|
+
# > DATA
|
73
|
+
# > ==========================================================================================================
|
74
|
+
base.scene :unknown, { level: :unknown, mask: { clr: :gray }, payload: [[:mask, ' [%{subject}] '], :__data__, :mask] } do |data, *args|
|
75
|
+
subject, opts = _scene_subject_with_opts(args, 'Unknown')
|
76
|
+
self.log data, _scene_opt(:unknown, { subject: subject }, opts)
|
77
|
+
end
|
78
|
+
|
62
79
|
# success method
|
63
80
|
# log level @ success (sub-level of info)
|
64
81
|
# prints: enclosed data
|
@@ -66,7 +83,8 @@ module RubySmart
|
|
66
83
|
# > ================================================ [Success] ================================================
|
67
84
|
# > DATA
|
68
85
|
# > ===========================================================================================================
|
69
|
-
base.scene :success, { level: :success, mask: { clr: :green }, payload: [[:mask, ' [%{subject}] '], :__data__, :mask] } do |data,
|
86
|
+
base.scene :success, { level: :success, mask: { clr: :green }, payload: [[:mask, ' [%{subject}] '], :__data__, :mask] } do |data, *args|
|
87
|
+
subject, opts = _scene_subject_with_opts(args, 'Success')
|
70
88
|
self.log data, _scene_opt(:success, { subject: subject }, opts)
|
71
89
|
end
|
72
90
|
|
@@ -287,34 +305,52 @@ module RubySmart
|
|
287
305
|
# log level @ debug
|
288
306
|
# prints: a processed output with unicode box-chars (e.g. ║ )
|
289
307
|
#
|
290
|
-
# ╔ START
|
308
|
+
# ╔ START ❯ job
|
291
309
|
# ╟ doing some cool log
|
292
310
|
# ╟ doing some extra log
|
293
|
-
# ╚ END [
|
311
|
+
# ╚ END ❯ job [SUCCESS] (duration: 4.34223)
|
294
312
|
base.scene :processed, { level: :debug } do |name, opts = {}, &block|
|
295
|
-
#
|
313
|
+
# increase level
|
296
314
|
lvl = processed_lvl(:up)
|
297
315
|
|
298
|
-
#
|
299
|
-
|
300
|
-
|
316
|
+
# resolve a new time-key.
|
317
|
+
# The key depends on the current level - this should be possible, since processes on the same level should not be possible
|
318
|
+
timer_key = if opts[:timer]
|
319
|
+
"processed_#{lvl}"
|
320
|
+
else
|
321
|
+
nil
|
322
|
+
end
|
323
|
+
|
324
|
+
begin
|
325
|
+
# starts new time (if key was created)
|
326
|
+
self.timer(:start, timer_key)
|
327
|
+
|
328
|
+
# send START name as +data+ - the full log line is created through the +_pcd+ method.
|
329
|
+
self.log(name, _scene_opt(:processed, opts, { pcd: :start }))
|
330
|
+
|
331
|
+
# run the provided block and resolve result
|
332
|
+
result_str = case block.call
|
333
|
+
when true
|
334
|
+
'[SUCCESS]'.bg_green + ' '
|
335
|
+
when false
|
336
|
+
'[FAIL]'.bg_red + ' '
|
337
|
+
else
|
338
|
+
''
|
339
|
+
end
|
340
|
+
rescue => e
|
341
|
+
self.fatal("#{e.message} @ #{e.backtrace_locations&.first}") unless opts[:silent]
|
342
|
+
# reraise exception
|
343
|
+
raise
|
344
|
+
ensure
|
345
|
+
result_str ||= ''
|
346
|
+
|
347
|
+
# 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)})" : '')}", _scene_opt(:processed, opts, { pcd: :end }))
|
349
|
+
|
350
|
+
# reduce level
|
351
|
+
processed_lvl(:down)
|
301
352
|
end
|
302
353
|
|
303
|
-
self.log("START :: #{name}", _scene_opt(:processed, opts, { pcd: :start }))
|
304
|
-
|
305
|
-
end_str = case block.call
|
306
|
-
when true
|
307
|
-
'SUCCESS'
|
308
|
-
when false
|
309
|
-
'FAILED'
|
310
|
-
else
|
311
|
-
name
|
312
|
-
end
|
313
|
-
|
314
|
-
self.log("END [#{end_str}] #{(timer_key ? "(duration: #{self.timer(:clear, timer_key, humanized: true)})" : '')}", _scene_opt(:processed, opts, { pcd: :end }))
|
315
|
-
|
316
|
-
processed_lvl(:down)
|
317
|
-
|
318
354
|
true
|
319
355
|
end
|
320
356
|
end
|
@@ -40,4 +40,6 @@ Gem::Specification.new do |spec|
|
|
40
40
|
spec.add_development_dependency 'rake', '~> 13.0'
|
41
41
|
spec.add_development_dependency 'rspec', '~> 3.0'
|
42
42
|
spec.add_development_dependency 'yard', '~> 0.9'
|
43
|
+
spec.add_development_dependency 'yard-activesupport-concern', '~> 0.0.1'
|
44
|
+
spec.add_development_dependency 'yard-relative_markdown_links', '>= 0.4'
|
43
45
|
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.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tobias Gonsior
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-08-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ruby_smart-support
|
@@ -94,6 +94,34 @@ dependencies:
|
|
94
94
|
- - "~>"
|
95
95
|
- !ruby/object:Gem::Version
|
96
96
|
version: '0.9'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: yard-activesupport-concern
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: 0.0.1
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: 0.0.1
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: yard-relative_markdown_links
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0.4'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0.4'
|
97
125
|
description: "RubySmart::SimpleLogger is a fast, customizable logging library with
|
98
126
|
multi-device support, \nspecial (PRE-defined) scenes for better logging visibility.\n"
|
99
127
|
email:
|
@@ -146,7 +174,7 @@ metadata:
|
|
146
174
|
documentation_uri: https://rubydoc.info/gems/ruby_smart-simple_logger
|
147
175
|
changelog_uri: https://github.com/ruby-smart/simple_logger/blob/main/docs/CHANGELOG.md
|
148
176
|
allowed_push_host: https://rubygems.org
|
149
|
-
post_install_message:
|
177
|
+
post_install_message:
|
150
178
|
rdoc_options: []
|
151
179
|
require_paths:
|
152
180
|
- lib
|
@@ -161,8 +189,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
161
189
|
- !ruby/object:Gem::Version
|
162
190
|
version: '0'
|
163
191
|
requirements: []
|
164
|
-
rubygems_version: 3.
|
165
|
-
signing_key:
|
192
|
+
rubygems_version: 3.4.10
|
193
|
+
signing_key:
|
166
194
|
specification_version: 4
|
167
195
|
summary: A simple, multifunctional logging library for Ruby.
|
168
196
|
test_files: []
|