ruby_smart-simple_logger 1.1.1 → 1.2.1

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: c9d250fc038e12f5d76ede43d6714efb039be7b6093bd4ea8abca6dfc937d8cc
4
- data.tar.gz: 52d4bc7495fea29db91b336161b7af454d55b9f22e76f1e83291264844686df7
3
+ metadata.gz: d4f5d3ae3592f31b6c012044205c37d859c9e809d58f8cce63c7b6b2ed634829
4
+ data.tar.gz: d50becd65a8386e2466ddebcbbbd6bf2ec92aad95f4c5ae76288974429d607bc
5
5
  SHA512:
6
- metadata.gz: cf60c99604f5da1abd4bc4ffa5c536c233728c242c7c198849fd1838cacf856a0abaaef39f6cb1aa46fc9adbd85be329637f01e0844c39e43bdac660db311a20
7
- data.tar.gz: 7c618af918fd6a19228f152fd456a8a4f2d99bbeceae1aec4d2aa6706f11f2138ba575390d68076f2d07e29fe09fbcdce75c64baed06a887becb752662f391bd
6
+ metadata.gz: dbe6aab96f5a2f67f85fd5147462d65e0f8496a1271406710f4d9e8b5df3a245c8f7e1292a9ac3f548973a204442332abafe21a8a97b6724f25a513b3eef7148
7
+ data.tar.gz: 5165beba92525197a3d9359bc7513c15e4aa6057a3bea5902870541141fe9ca4fdb3b4f6270eefcbbbf7ca75aff209e03cf39d4d8eb00d34e3292a45e71960ad
data/README.md CHANGED
@@ -112,6 +112,8 @@ logger = ::SimpleLogger.new
112
112
  logger.debug "some debug"
113
113
  logger.error "that failed ..."
114
114
 
115
+ # ----------------------------------------------------------------------------------------------------------------------
116
+
115
117
  alternative_logger = ::SimpleLogger.new :memory
116
118
  alternative_logger.debug "some debug, just in memory logs"
117
119
  alternative_logger.error "that failed, also in memory logs..."
@@ -123,6 +125,16 @@ alternative_logger.logs
123
125
  # access the logs as grouped hash
124
126
  alternative_logger.logs_to_h
125
127
  #=> {:debug=>["some debug, just in memory logs"], :error=>["that failed, also in memory logs..."]}
128
+
129
+ # ----------------------------------------------------------------------------------------------------------------------
130
+
131
+ multi_logger = ::SimpleLogger.new :memory, :stdout, clr: true, format: :default
132
+ multi_logger.debug "some debug, sent to stdout & memory"
133
+ # > D, [2023-02-15T10:22:45.030758 #13397] DEBUG -- : some debug, sent to stdout & memory
134
+
135
+ # access the logs as array
136
+ multi_logger.logs
137
+ # => [[:debug, 2023-02-15T10:22:45 +0200, "some debug, sent to stdout & memory"]]
126
138
  ```
127
139
  _You can also create a new instance from every klass_logger Object (see below)._
128
140
 
@@ -142,7 +154,6 @@ MyCustomLogger.theme "My Theme"
142
154
 
143
155
  # log directly to a customized logfile - created through the builtin module name
144
156
  MyCustomLogger.klass_logger_opts = {builtin: MyApp::Tasks::SpecialTask}
145
- MyCustomLogger.clear!
146
157
  MyCustomLogger.info "Very nice here"
147
158
  # => creates a logfile @ log/my_app/tasks/special_task.log
148
159
  ```
@@ -156,7 +167,6 @@ SimpleLogger.error "that failed ..."
156
167
 
157
168
  # resetting options
158
169
  SimpleLogger.klass_logger_opts = {builtin: :memory, stdout: false}
159
- SimpleLogger.clear!
160
170
 
161
171
  SimpleLogger.debug "some other debug in memory only ..."
162
172
  SimpleLogger.logs
@@ -167,13 +177,14 @@ other_logger = SimpleLogger.new
167
177
  other_logger.debug "some other debug in memory only ..."
168
178
 
169
179
  # create new logger, but don't use 'klass_logger_opts' - instead pipe to the rails logger
170
- other_logger2 = SimpleLogger.new :rails
180
+ other_logger2 = SimpleLogger.new :rails, :stdout
171
181
  other_logger2.info "directly logs to the rails logger"
182
+ other_logger2.info "and also to STDOUT"
172
183
  ```
173
184
 
174
- Alternatives with 'Debugger':
185
+ Alternatives with already build 'Debugger':
175
186
  ```ruby
176
- require 'debugger'
187
+ require 'ruby_smart-debugger'
177
188
 
178
189
  Debugger.debug "some debug"
179
190
  Debugger.error "that failed ..."
@@ -530,7 +541,7 @@ logger.debug({ a: 1, b: 2 })
530
541
 
531
542
  ## _defaults_
532
543
 
533
- Logger default options are still available: ```shift_age, shift_size, progname, datetime_format, shift_period_suffix```
544
+ Device default options are still available: ```shift_age, shift_size, progname, datetime_format, shift_period_suffix, binmode```
534
545
 
535
546
  -----
536
547
 
@@ -737,19 +748,19 @@ l.processed("Process Alpha", timer: true) do
737
748
  end
738
749
 
739
750
 
740
- # ╔ START - Process Alpha
751
+ # ╔ START :: Process Alpha
741
752
  # ╟ find files
742
753
  # ╟ found 34 files
743
- # ║ ┌ START - extracting ...
754
+ # ║ ┌ START :: extracting ...
744
755
  # ║ ├ 10% done
745
756
  # ║ ├ 20% done
746
757
  # ║ ├ 100% done
747
- # ║ └ END - SUCCESS (duration: 0.000267545)
748
- # ║ ┌ START - transforming ...
758
+ # ║ └ END [SUCCESS] (duration: 0.000267545)
759
+ # ║ ┌ START :: transforming ...
749
760
  # ║ ├ bad memory
750
761
  # ║ ├ rolling back
751
- # ║ └ END - FAILED
752
- # ╚ END - Process Alpha (duration: 0.001040807)
762
+ # ║ └ END [FAILED]
763
+ # ╚ END [Process Alpha] (duration: 0.001040807)
753
764
  ```
754
765
 
755
766
  ### _other useful methods_
data/docs/CHANGELOG.md CHANGED
@@ -1,5 +1,21 @@
1
1
  # RubySmart::SimpleLogger - CHANGELOG
2
2
 
3
+ ## [1.2.1] - 2023-02-17
4
+ * **[fix]** 'rails'-related builtins
5
+ * **[fix]** `::RubySmart::SimpleLogger::Devices::MultiDevice` register `MultiDevice` instead of nested devices
6
+
7
+ ## [1.2.0] - 2023-02-16
8
+ * **[add]** multi-'builtins' support
9
+ * **[ref]** `Logger` initialization - now supports to provide multiple builtins
10
+ * **[ref]** `Debugger` requirement to 'ruby_smart-debugger' instead of 'debugger'
11
+ * **[ref]** 'processed' scene to be moved to 'debug'-severity
12
+ * **[fix]** some contradictions within the builtins
13
+ * **[fix]** nested 'logdev' relation with `::RubySmart::SimpleLogger::Devices::MultiDevice` devices
14
+ * **[fix]** `::RubySmart::SimpleLogger::KlassLogger` not forwarding optional block to scenes
15
+ * **[fix]** overcomplicated initialization with ruby's logger - now creates it own logdev
16
+ * **[fix]** `Debugger` conflict with `ruby-debug-ide`-gem
17
+ * **[fix]** 'date_helper' initialisation
18
+
3
19
  ## [1.1.1] - 2023-02-07
4
20
  * **[fix]** 'ruby 2.6.x' kwargs for `::Logger::LogDevice` messed up with 'binmode'
5
21
 
@@ -53,10 +53,15 @@ module RubySmart
53
53
  #
54
54
  # @param [Object] dev
55
55
  def register(dev, formatter = nil)
56
- @devices << {
57
- dev: dev,
58
- formatter: formatter
59
- }
56
+ # check device, to prevent nested sets of +MultiDevice+
57
+ if dev.is_a?(MultiDevice)
58
+ @devices += dev.devices
59
+ else
60
+ @devices << {
61
+ dev: dev,
62
+ formatter: formatter
63
+ }
64
+ end
60
65
 
61
66
  self
62
67
  end
@@ -11,104 +11,187 @@ module RubySmart
11
11
 
12
12
  private
13
13
 
14
- # prepare builtin defaults
14
+ # set / overwrite default opts
15
15
  # @param [Hash] opts
16
- # @param [Object] builtin
17
- def _opts_builtin(opts, builtin = nil)
18
- builtin ||= opts.delete(:builtin)
16
+ def _opts_init!(opts)
17
+ ##################################################################################
18
+ # level
19
+
20
+ # initialize a default rails-dependent output
21
+ if ::ThreadInfo.rails?
22
+ opts[:level] ||= (::Rails.env.production? ? :info : :debug)
23
+ end
24
+
25
+ # clean & rewrite level (possible symbols) to real level
26
+ opts[:level] = _level(opts[:level] || :debug)
27
+
28
+ ##################################################################################
29
+ # mask
30
+
31
+ # set mask from options
32
+ self.mask(opts[:mask]) if opts[:mask]
33
+
34
+ # disable mask color if explicit disabled
35
+ self.mask(clr: false) if opts[:clr] == false
36
+
37
+ # reduce mask-size to window size
38
+ if ::ThreadInfo.windowed? && ::ThreadInfo.winsize[1] < self.mask[:length]
39
+ self.mask(length: ::ThreadInfo.winsize[1])
40
+ end
41
+
42
+ ##################################################################################
43
+ # instance related
44
+
45
+ # ignore payload and send data directly to the logdev
46
+ @ignore_payload = true if @ignore_payload.nil? && opts[:payload] == false
47
+
48
+ # set the inspector to be used for data inspection.
49
+ # 'disable' inspector, if false was provided - which simply results in +#to_s+
50
+ @inspector = (opts[:inspect] == false) ? :to_s : opts[:inspector]
51
+
52
+ # prevent to return any data
53
+ nil
54
+ end
55
+
56
+ # enhance provided opts with +:device+.
57
+ # opts may be manipulated by resolved device
58
+ # does not return any data.
59
+ # @param [Hash] opts
60
+ def _opts_device!(opts)
61
+ # check for already existing +device+
62
+ return if opts[:device]
63
+
64
+ # remove builtin key from opts
65
+ builtin = opts.delete(:builtin)
66
+
67
+ # retransform array into single value
68
+ builtin = builtin[0] if builtin.is_a?(Array) && builtin.length < 2
69
+
70
+ # expand current builtin with optional provided keywords
71
+ if opts.delete(:stdout)
72
+ builtin = [builtin] unless builtin.is_a?(Array)
73
+ builtin << :stdout
74
+ end
75
+
76
+ if opts.delete(:memory)
77
+ builtin = [builtin] unless builtin.is_a?(Array)
78
+ builtin << :memory
79
+ end
80
+
81
+ # determinate builtin - first check to create +MultiDevice+.
82
+ if builtin.is_a?(Array)
83
+ opts[:device] = ::RubySmart::SimpleLogger::Devices::MultiDevice.new
84
+ builtin.uniq.each do |key|
85
+ # IMPORTANT: dup, original hash to prevent reference manipulation (on the TOP-level, only)
86
+ builtin_opts = opts.dup
87
+ opts[:device].register(_resolve_device(key, builtin_opts), _resolve_formatter(builtin_opts))
88
+ end
89
+
90
+ # force 'passthrough', as format, since this is required for multi-devices
91
+ opts[:format] = :passthrough
92
+ else
93
+ opts[:device] = _resolve_device(builtin, opts)
94
+ end
95
+
96
+ # prevent to return any data
97
+ nil
98
+ end
99
+
100
+ # enhance provided opts with +:formatter+.
101
+ # opts may be manipulated by resolved formatter
102
+ # does not return any data.
103
+ # @param [Hash] opts
104
+ def _opts_formatter!(opts)
105
+ # check for already existing +formatter+
106
+ return if opts[:formatter]
107
+
108
+ opts[:formatter] = _resolve_formatter(opts)
109
+
110
+ # prevent to return any data
111
+ nil
112
+ end
113
+
114
+ # resolves & returns formatter from provided opts
115
+ # @param [Hash] opts
116
+ # @return [RubySmart::SimpleLogger::Formatter]
117
+ def _resolve_formatter(opts)
118
+ # set default format
119
+ opts[:format] ||= :plain
120
+
121
+ # fix nl - which depends on other opts
122
+ opts[:nl] = _nl(opts)
123
+
124
+ # fix clr
125
+ opts[:clr] = true if opts[:clr].nil?
126
+
127
+ ::RubySmart::SimpleLogger::Formatter.new(opts)
128
+ end
19
129
 
130
+ # resolves & returns device from builtin & provided opts
131
+ # @param [Object] builtin
132
+ # @param [Hash] opts
133
+ def _resolve_device(builtin, opts)
20
134
  case builtin
21
- when nil
22
- # device is nil - resolve optimal device
135
+ when nil # builtin is nil - resolve optimal device for current environment
23
136
  if ::ThreadInfo.stdout?
24
- _opts_builtin(opts, :stdout)
137
+ _resolve_device(:stdout, opts)
25
138
  elsif ::ThreadInfo.rails? && ::Rails.logger
26
- _opts_builtin(opts, :rails)
139
+ _resolve_device(:rails, opts)
27
140
  else
28
- _opts_builtin(opts, :memory)
141
+ _resolve_device(:memory, opts)
29
142
  end
30
143
  when :stdout
31
- # set device ONLY if unset in opts
32
- opts[:device] ||= STDOUT
33
- # colorize output
34
- opts[:clr] = true if opts[:clr].nil?
144
+ STDOUT
35
145
  when :stderr
36
- opts[:device] ||= STDERR
37
- # colorize output
38
- opts[:clr] = true if opts[:clr].nil?
146
+ STDERR
39
147
  when :rails
40
- # set device ONLY if unset in opts
41
- opts[:device] ||= ::RubySmart::SimpleLogger::Devices::MultiDevice.register(::Rails.logger.instance_variable_get(:@logdev).dev)
148
+ raise "Unable to build SimpleLogger with 'rails' builtin for not initialized rails application!" unless ThreadInfo.rails?
149
+
150
+ # special check for rails-with-console (IRB -> STDOUT) combination - mostly in combination with +Debase+.
151
+ if ThreadInfo.console? && ::Rails.logger.instance_variable_get(:@logdev).dev != STDOUT
152
+ ::RubySmart::SimpleLogger::Devices::MultiDevice
153
+ .register(_resolve_device(:stdout, opts))
154
+ .register(::Rails.logger.instance_variable_get(:@logdev).dev)
155
+ else
156
+ ::Rails.logger.instance_variable_get(:@logdev).dev
157
+ end
42
158
  when :proc
43
- # auto sets related opts for proc device
44
- opts[:payload] = false
159
+ # force overwrite opts
160
+ @ignore_payload = true
45
161
  opts[:nl] = false
46
- opts[:format] ||= :passthrough
162
+ opts[:format] = :passthrough
47
163
 
48
- # set device ONLY if unset in opts
49
- opts[:device] ||= ::RubySmart::SimpleLogger::Devices::ProcDevice.new(opts[:proc])
164
+ ::RubySmart::SimpleLogger::Devices::ProcDevice.new(opts.delete(:proc))
50
165
  when :memory
51
- # auto sets related opts for memory device
52
- opts[:payload] = false
53
-
54
- # set device ONLY if unset in opts
55
- opts[:device] ||= if opts[:stdout]
56
- # store original format
57
- stdout_format = opts[:format] || :plain
58
-
59
- # force 'passthrough', as format, since this is required for multi-devices
60
- opts[:format] = :passthrough
61
-
62
- # special case handling to additionally stdout logs
63
- ::RubySmart::SimpleLogger::Devices::MultiDevice.new
64
- .register(::RubySmart::SimpleLogger::Devices::MemoryDevice.new, ::RubySmart::SimpleLogger::Formatter.new(format: :memory))
65
- .register(STDOUT, ::RubySmart::SimpleLogger::Formatter.new(format: stdout_format, nl: _nl(opts), clr: opts[:clr]))
66
- else
67
- opts[:format] ||= :memory
68
- ::RubySmart::SimpleLogger::Devices::MemoryDevice.new
69
- end
70
- when Module
71
- # set device ONLY if unset in opts
72
- opts[:device] ||= if opts[:stdout]
73
- # store original format
74
- device_format = opts[:format] || :plain
75
-
76
- # force 'passthrough', as format, since this is required for multi-devices
77
- opts[:format] = :passthrough
78
-
79
- # colorize output
80
- opts[:clr] = true if opts[:clr].nil?
81
-
82
- # special case handling to additionally stdout logs
83
- ::RubySmart::SimpleLogger::Devices::MultiDevice.register(
84
- if GemInfo.match?(RUBY_VERSION, '< 2.7')
85
- ::Logger::LogDevice.new(_logdev(builtin),
86
- shift_age: opts[:shift_age] || 0,
87
- shift_size: opts[:shift_size] || 1048576,
88
- shift_period_suffix: opts[:shift_period_suffix])
89
- else
90
- ::Logger::LogDevice.new(_logdev(builtin),
91
- shift_age: opts[:shift_age] || 0,
92
- shift_size: opts[:shift_size] || 1048576,
93
- shift_period_suffix: opts[:shift_period_suffix],
94
- binmode: opts[:binmode])
95
- end,
96
- ::RubySmart::SimpleLogger::Formatter.new(format: device_format, nl: _nl(opts), clr: false))
97
- .register(STDOUT, ::RubySmart::SimpleLogger::Formatter.new(format: device_format, nl: _nl(opts), clr: opts[:clr]))
98
- else
99
- builtin
100
- end
166
+ # force overwrite opts
167
+ @ignore_payload = true
168
+ opts[:format] = :memory
169
+
170
+ ::RubySmart::SimpleLogger::Devices::MemoryDevice.new
171
+ when Module, String
172
+ # force overwrite opts
173
+ opts[:clr] = false
174
+ _logdev(opts, builtin)
101
175
  else
102
- # forward provided device ONLY if unset in opts
103
- opts[:device] ||= builtin
176
+ _logdev(opts, builtin)
104
177
  end
105
178
  end
106
179
 
107
180
  # resolve the final log-device from provided param
181
+ # @param [Hash] opts
108
182
  # @param [Object] device
109
- # @return [Object]
110
- def _logdev(device)
111
- if device.is_a?(Module)
183
+ # @return [:Logger::LogDevice]
184
+ def _logdev(opts, device = nil)
185
+ device ||= opts.delete(:device)
186
+
187
+ # if existing device is already writeable, simply return it
188
+ return device if device.respond_to?(:write)
189
+
190
+ file_location = nil
191
+
192
+ # resolve the file_location from provided device
193
+ case device
194
+ when Module
112
195
  devstring = device.to_s
113
196
  logfile = (devstring.respond_to?(:underscore) ? devstring.underscore : _underscore(device.to_s)) + '.log'
114
197
  # check for rails
@@ -122,23 +205,36 @@ module RubySmart
122
205
  file_path = File.dirname(file_location)
123
206
  FileUtils.mkdir_p(file_path) unless File.directory?(file_path)
124
207
 
208
+ # the logdev
125
209
  file_location
126
- elsif device.is_a?(String)
127
- device = "log/#{device}" unless device[0] == '/'
210
+ when String
211
+ file_location = (device[0] == '/' ? device : "log/#{device}")
128
212
 
129
213
  # resolve path to create a folder
130
- file_path = File.dirname(device)
214
+ file_path = File.dirname(file_location)
131
215
  FileUtils.mkdir_p(file_path) unless File.directory?(file_path)
132
216
 
133
- device
134
- elsif device.respond_to?(:write)
135
- device
217
+ file_location
136
218
  else
137
- raise "SimpleLogger :: device '#{device}' must respond to 'write'!"
219
+ raise "Unable to build SimpleLogger! The provided device '#{device}' must respond to 'write'!"
220
+ end
221
+
222
+ if GemInfo.match?(RUBY_VERSION, '< 2.7')
223
+ ::Logger::LogDevice.new(file_location,
224
+ shift_age: opts[:shift_age] || 0,
225
+ shift_size: opts[:shift_size] || 1048576,
226
+ shift_period_suffix: opts[:shift_period_suffix])
227
+ else
228
+ ::Logger::LogDevice.new(file_location,
229
+ shift_age: opts[:shift_age] || 0,
230
+ shift_size: opts[:shift_size] || 1048576,
231
+ shift_period_suffix: opts[:shift_period_suffix],
232
+ binmode: opts[:binmode])
138
233
  end
139
234
  end
140
235
 
141
236
  # this is a 1:1 copy of +String#underscore+ @ activesupport gem
237
+ # and only used if activesupport is not available ...
142
238
  def _underscore(camel_cased_word)
143
239
  return camel_cased_word unless /[A-Z-]|::/.match?(camel_cased_word)
144
240
  word = camel_cased_word.to_s.gsub("::", "/")
@@ -150,52 +246,6 @@ module RubySmart
150
246
  word
151
247
  end
152
248
 
153
- # build log-device & options on initialize
154
- # @param [Hash] opts
155
- # @return [Array<logdev,opts>] logdev, opts
156
- def _init_opts(opts)
157
- # clean & rewrite opts (especially device) to a real logdev
158
- _opts_builtin(opts)
159
-
160
- # set mask from options
161
- self.mask(opts[:mask]) if opts[:mask]
162
-
163
- # disable mask color if explicit disabled
164
- self.mask(clr: false) if opts[:clr] == false
165
-
166
- # reduce mask-size to window size
167
- if ::ThreadInfo.windowed? && ::ThreadInfo.winsize[1] < self.mask[:length]
168
- self.mask(length: ::ThreadInfo.winsize[1])
169
- end
170
-
171
- # initialize a default rails-dependent output
172
- if ::ThreadInfo.rails?
173
- opts[:level] ||= (::Rails.env.production? ? :info : :debug)
174
- end
175
-
176
- # clean & rewrite level (possible symbols) to real level
177
- opts[:level] = _level(opts[:level] || :debug)
178
-
179
- # clean & rewrite nl
180
- opts[:nl] = _nl(opts)
181
-
182
- # rewrite format
183
- opts[:format] ||= :plain
184
-
185
- # provide custom formatter and forward special opts (format, nl, clr)
186
- opts[:formatter] ||= ::RubySmart::SimpleLogger::Formatter.new(opts)
187
-
188
- # ignore payload and send data directly to the logdev
189
- @ignore_payload = true if opts[:payload].is_a?(FalseClass)
190
-
191
- # set the inspector to be used for data inspection.
192
- # 'disable' inspector, if false was provided - which simply results in +#to_s+
193
- @inspector = (opts[:inspect] === false) ? :to_s : opts[:inspector]
194
-
195
- # simple return opts
196
- opts
197
- end
198
-
199
249
  # returns the +nl+ (new line) flag, depending on the provided options.
200
250
  # recognizes +:nl+ and +:payload+ options.
201
251
  # @param [Hash] opts
@@ -247,8 +297,8 @@ module RubySmart
247
297
  # @param [String] str
248
298
  # @param [String, Symbol, nil] color
249
299
  # @return [String] colored string
250
- def _clr(str, color)
251
- return str unless color && str.respond_to?(color)
300
+ def _clr(str, color = nil)
301
+ return str unless color
252
302
  str.send(color) rescue str
253
303
  end
254
304
 
@@ -7,8 +7,8 @@ module RubySmart
7
7
  # returns the logdev logs
8
8
  # @return [Array]
9
9
  def logs
10
- return [] unless logdev.dev.respond_to?(:logs)
11
- logdev.dev.logs
10
+ return [] unless logdev.respond_to?(:logs)
11
+ logdev.logs
12
12
  end
13
13
 
14
14
  # transforms the logs-array into a hash of logs, grouped by level (:error, :success, ...)
@@ -9,7 +9,7 @@ module RubySmart
9
9
 
10
10
  module VERSION
11
11
  MAJOR = 1
12
- MINOR = 1
12
+ MINOR = 2
13
13
  TINY = 1
14
14
  PRE = nil
15
15
 
@@ -19,14 +19,13 @@ module RubySmart
19
19
  class_variable_set('@@klass_logger_opts', opts)
20
20
  end
21
21
 
22
- # delegate new method to logger
22
+ # delegate new method to Logger
23
23
  def new(*args)
24
- args = [nil, self.klass_logger_opts.dup] if args.length == 0
25
24
  RubySmart::SimpleLogger::Logger.new(*args)
26
25
  end
27
26
 
28
27
  def klass_logger
29
- @klass_logger ||= self.new
28
+ @klass_logger ||= self.new(self.klass_logger_opts.dup)
30
29
  end
31
30
 
32
31
  def clear!
@@ -34,7 +33,7 @@ module RubySmart
34
33
  end
35
34
 
36
35
  def method_missing(name, *args, &block)
37
- return self.klass_logger.send(name, *args) if self.klass_logger.respond_to? name
36
+ return self.klass_logger.send(name, *args, &block) if self.klass_logger.respond_to? name
38
37
  super
39
38
  end
40
39
 
@@ -40,30 +40,30 @@ module RubySmart
40
40
  # defines a uniq key to parse the data
41
41
  PAYLOAD_DATA_KEY = :__data__
42
42
 
43
- # initialize new Logger
44
- # @param [Object, Symbol, nil] builtin
45
- # @param [Hash] opts
46
- # @option opts [Symbol] :format - defines a custom format
47
- def initialize(builtin = nil, opts = nil)
48
- # check if only a hash was provided
49
- if opts.nil? && builtin.is_a?(Hash)
50
- opts = builtin
51
- else
52
- opts ||= {}
43
+ # initializes a new Logger
44
+ #
45
+ # @param [Array] args (<builtin>,<opts>) OR (<builtin>) OR (<opts>)
46
+ # @option args[Symbol,Array] <builtin> - provide a builtin, either a single symbol or array of symbols
47
+ # @option args[Hash] <options> - provide custom options
48
+ def initialize(*args)
49
+ opts = args.last.is_a?(Hash) ? args.pop : {}
50
+ opts[:builtin] = args if args.length > 0
53
51
 
54
- # extend builtin option if not set
55
- opts[:builtin] = builtin unless opts[:builtin]
56
- end
52
+ # enhance options with device & formatter
53
+ _opts_device!(opts)
54
+ _opts_formatter!(opts)
57
55
 
58
- # initialize provided opts
59
- o = _init_opts(opts)
56
+ # initialize & set defaults by provided opts
57
+ _opts_init!(opts)
60
58
 
61
- super(
62
- _logdev(o[:device]),
63
- o[:shift_age] || 0,
64
- o[:shift_size] || 1048576,
65
- **o.slice(:level, :progname, :formatter, :datetime_format, :binmode, :shift_period_suffix)
66
- )
59
+ # initialize with a nil +logdev+ to prevent any nested +LogDevice+ creation.
60
+ # we already arranged device & formatter to be able to respond to ther required methods
61
+ super(nil)
62
+
63
+ # set explicit after called super
64
+ self.level = opts[:level]
65
+ self.formatter = opts[:formatter]
66
+ @logdev = _logdev(opts)
67
67
  end
68
68
 
69
69
  # overwrite level setter, to accept every available (also newly defined) Severity
@@ -284,14 +284,14 @@ module RubySmart
284
284
  end
285
285
 
286
286
  # processed method
287
- # log level @ info
287
+ # log level @ debug
288
288
  # prints: a processed output with unicode box-chars (e.g. ║ )
289
289
  #
290
- # ╔ START job
290
+ # ╔ START :: job
291
291
  # ╟ doing some cool log
292
292
  # ╟ doing some extra log
293
- # ╚ END job (duration: 4.34223)
294
- base.scene :processed, { level: :info } do |name, opts = {}, &block|
293
+ # ╚ END [job] (duration: 4.34223)
294
+ base.scene :processed, { level: :debug } do |name, opts = {}, &block|
295
295
  # resolve the current process-level
296
296
  lvl = processed_lvl(:up)
297
297
 
@@ -300,18 +300,18 @@ module RubySmart
300
300
  self.timer(:start, timer_key) if timer_key
301
301
  end
302
302
 
303
- self.log("START - #{name}", _scene_opt(:processed, { pcd: :start }))
303
+ self.log("START :: #{name}", _scene_opt(:processed, opts, { pcd: :start }))
304
304
 
305
305
  end_str = case block.call
306
306
  when true
307
- "END - SUCCESS"
307
+ 'SUCCESS'
308
308
  when false
309
- "END - FAILED"
309
+ 'FAILED'
310
310
  else
311
- "END - #{name}"
311
+ name
312
312
  end
313
313
 
314
- self.log("#{end_str} #{(timer_key ? "(duration: #{self.timer(:clear, timer_key, :humanized => true)})" : '')}", _scene_opt(:processed, { pcd: :end }))
314
+ self.log("END [#{end_str}] #{(timer_key ? "(duration: #{self.timer(:clear, timer_key, humanized: true)})" : '')}", _scene_opt(:processed, opts, { pcd: :end }))
315
315
 
316
316
  processed_lvl(:down)
317
317
 
@@ -18,7 +18,7 @@ end
18
18
 
19
19
  # load date extensions for logger
20
20
  if GemInfo.loaded?('activesupport') && GemInfo.installed?('actionview')
21
- ActiveSupport.on_load(:action_view) do
21
+ ActiveSupport.on_load(:active_record) do
22
22
  require('action_view/helpers/date_helper')
23
23
  RubySmart::SimpleLogger::Logger.include(ActionView::Helpers::DateHelper)
24
24
  end
@@ -9,7 +9,7 @@ GemInfo.safe_require 'ruby-debug-ide'
9
9
  # try to load 'awesome_print', if available
10
10
  GemInfo.safe_require 'awesome_print'
11
11
 
12
- class Debugger
12
+ module Debugger
13
13
  extend ::RubySmart::SimpleLogger::KlassLogger
14
14
 
15
15
  # force debugger to 'DEBUG' severity
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.1.1
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tobias Gonsior
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2023-02-07 00:00:00.000000000 Z
11
+ date: 2023-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby_smart-support
@@ -114,7 +114,7 @@ files:
114
114
  - docs/CHANGELOG.md
115
115
  - docs/CODE_OF_CONDUCT.md
116
116
  - docs/LICENSE.txt
117
- - lib/debugger.rb
117
+ - lib/ruby_smart-debugger.rb
118
118
  - lib/ruby_smart-simple_logger.rb
119
119
  - lib/ruby_smart/simple_logger.rb
120
120
  - lib/ruby_smart/simple_logger/core_ext/ruby/string.rb