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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f93f509aad065f314393b0b7f630694091fb06c967bc20ad1fe4e0b7683f843b
4
- data.tar.gz: 9d5a325fac9bc01ad330cec1c1c31a9bc3f5602e1934893b04ab5f3baed22ac0
3
+ metadata.gz: 101c7a9ab2862c9ff3e7ace74f812a20a522dfa7fa8c6fcdf9f9accc53fd29e2
4
+ data.tar.gz: 1e1f7d6e1c9cbfe48a21cc8cceaa7cd37de7712363ae78e80bcff87aa6c5ca5a
5
5
  SHA512:
6
- metadata.gz: 5b4b91d4c70cd0e373af89191b9147739a55443e851ffdc8751e3853d833e04f59cd9aa6d125a60c752e924686a190d8bd492560860e91d18749af48adc210d4
7
- data.tar.gz: 5cb89dd0a2cf9b77f3ce2cbc4bcf7c9f8ee218fb9030a16c9bba0259ac5ca16bf82fcdffef2602533b567b2591d94f672662a46e3562b8a1fdee398980137718
6
+ metadata.gz: 875fc9ea64929088e6a445f43b1e3a0c7b1c92de106a53c8112c68a3eb28ab5ea081c2a1e21d7d672d7e3109c68e68a83283be41364d65b2c450b6932408e15a
7
+ data.tar.gz: 9be8b0019a5afb3b3a9050dcb6139d9cf2ffe9fbd89549ebb717e8e4a2b59ee981dad95948400836a78e8b8205a324dbd2a35dea6638567143e37cbc93425e32
@@ -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
- ruby-version: ['3.1', '3.0', '2.7', '2.6']
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
- - uses: actions/checkout@v3
29
- - name: Set up Ruby
30
- # To automatically get bug fixes and new Ruby versions for ruby/setup-ruby,
31
- # change this to (see https://github.com/ruby/setup-ruby#versioning):
32
- # uses: ruby/setup-ruby@v1
33
- uses: ruby/setup-ruby@0a29871fe2b0200a17a4497bae54fe5df0d973aa # v1.115.3
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 :: Process Alpha
751
+ # ╔ START Process Alpha
752
752
  # ╟ find files
753
753
  # ╟ found 34 files
754
- # ║ ┌ START :: extracting ...
754
+ # ║ ┌ START extracting ...
755
755
  # ║ ├ 10% done
756
756
  # ║ ├ 20% done
757
757
  # ║ ├ 100% done
758
- # ║ └ END [SUCCESS] (duration: 0.000267545)
759
- # ║ ┌ START :: transforming ...
758
+ # ║ └ END ❯ extracting ... [SUCCESS] (0.000244804)
759
+ # ║ ┌ START transforming ...
760
760
  # ║ ├ bad memory
761
761
  # ║ ├ rolling back
762
- # ║ └ END [FAILED]
763
- # ╚ END [Process Alpha] (duration: 0.001040807)
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 = true if @ignore_payload.nil? && opts[:payload] == false
43
+ @ignore_payload = true if @ignore_payload.nil? && opts[:payload] == false
47
44
 
48
- # set the inspector to be used for data inspection.
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] = _nl(opts)
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] = false
156
- opts[:format] = :passthrough
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] = :memory
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
- __default__: %w(╟ ├),
16
- __processed__: %w( ),
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 [nil, Symbol] handle - optional handle to increase or decrease the current lvl (+:up+ / +:down+)
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
- # nothing here ...
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 [Object] data
70
+ # @param [String] data
64
71
  # @param [Hash] opts
65
- # @return [Object,String]
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 lvl, once
77
+ # resolve the current level - either directly through the options or the +processed_lvl+.
71
78
  lvl = opts[:lvl] || processed_lvl
72
79
 
73
- # create final string
74
- lvl.times.map { |i| "#{_pcd_box_char(:__processed__, i)} " }.join + _pcd_box_char(opts[:pcd], lvl) + " #{data}"
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[:__default__]
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, _pcd(data, opts)
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 << _parse_data(data, (opts[:inspect] ? (opts[:inspector] || self.inspector) : nil))
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
- # just parses the data and calls an inspection method, if provided
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 [Symbol, nil] inspector - the inspection method to be called (e.g. :ai, :inspect, :to_s) - if not provided it tries to auto-resolve
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 _parse_data(data, inspector = nil)
130
- (inspector ? data.send(inspector) : data).to_s
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
- measure: 0
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][:measure] = 0
21
+ @timers[key][:total] = 0
20
22
 
21
23
  true
22
- when :start, :continue
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][:measure] += @timers[key][:stop] - @timers[key][:start]
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][:measure] += Time.now - @timers[key][:start]
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][:measure]
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/, '')
@@ -9,8 +9,8 @@ module RubySmart
9
9
 
10
10
  module VERSION
11
11
  MAJOR = 1
12
- MINOR = 2
13
- TINY = 2
12
+ MINOR = 3
13
+ TINY = 0
14
14
  PRE = nil
15
15
 
16
16
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
@@ -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, subject = 'Debug', opts = {}|
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, subject = 'Info', opts = {}|
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, subject = 'Warn', opts = {}|
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, subject = 'Error', opts = {}|
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, subject = 'Fatal', opts = {}|
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, subject = 'Success', opts = {}|
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 :: job
308
+ # ╔ START job
291
309
  # ╟ doing some cool log
292
310
  # ╟ doing some extra log
293
- # ╚ END [job] (duration: 4.34223)
311
+ # ╚ END job [SUCCESS] (duration: 4.34223)
294
312
  base.scene :processed, { level: :debug } do |name, opts = {}, &block|
295
- # resolve the current process-level
313
+ # increase level
296
314
  lvl = processed_lvl(:up)
297
315
 
298
- # start the timer, if it should - directly sets a timer key to be reused in the +:clear+ method
299
- if (timer_key = (opts[:timer] ? "processed_#{lvl}" : nil))
300
- self.timer(:start, timer_key) if timer_key
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.2.2
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-03-15 00:00:00.000000000 Z
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.3.26
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: []