ruby_smart-simple_logger 1.1.1 → 1.2.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: c9d250fc038e12f5d76ede43d6714efb039be7b6093bd4ea8abca6dfc937d8cc
4
- data.tar.gz: 52d4bc7495fea29db91b336161b7af454d55b9f22e76f1e83291264844686df7
3
+ metadata.gz: a47086748b62315efd5a4497e118bbb8a537cb153099cefa99e9432a8ed14ecb
4
+ data.tar.gz: 9f74e2177dfd4fb008fb8b203d282217a37846c724b4e2b0bfa55ae982ea83ef
5
5
  SHA512:
6
- metadata.gz: cf60c99604f5da1abd4bc4ffa5c536c233728c242c7c198849fd1838cacf856a0abaaef39f6cb1aa46fc9adbd85be329637f01e0844c39e43bdac660db311a20
7
- data.tar.gz: 7c618af918fd6a19228f152fd456a8a4f2d99bbeceae1aec4d2aa6706f11f2138ba575390d68076f2d07e29fe09fbcdce75c64baed06a887becb752662f391bd
6
+ metadata.gz: 50d2cb4beda62d0c4189c22eb201ae8cc95e1cf6d9e0f037522f58c27ce3ddf34a000fba9156a71b662b223313fe2cdd4d5589916094cbe19b71393220e62464
7
+ data.tar.gz: 723da7c50cc2d87ea2c8de011c0f54d743c32c5abf99da5441a5cf6a6cec7657ec4dd35de3d67ab6d3cc9ed8b95db01c0ef702a20a6d33b8a25d1f1ba7ab34dc
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,17 @@
1
1
  # RubySmart::SimpleLogger - CHANGELOG
2
2
 
3
+ ## [1.2.0] - 2023-02-16
4
+ * **[add]** multi-'builtins' support
5
+ * **[ref]** `Logger` initialization - now supports to provide multiple builtins
6
+ * **[ref]** `Debugger` requirement to 'ruby_smart-debugger' instead of 'debugger'
7
+ * **[ref]** 'processed' scene to be moved to 'debug'-severity
8
+ * **[fix]** some contradictions within the builtins
9
+ * **[fix]** nested 'logdev' relation with `::RubySmart::SimpleLogger::Devices::MultiDevice` devices
10
+ * **[fix]** `::RubySmart::SimpleLogger::KlassLogger` not forwarding optional block to scenes
11
+ * **[fix]** overcomplicated initialization with ruby's logger - now creates it own logdev
12
+ * **[fix]** `Debugger` conflict with `ruby-debug-ide`-gem
13
+ * **[fix]** 'date_helper' initialisation
14
+
3
15
  ## [1.1.1] - 2023-02-07
4
16
  * **[fix]** 'ruby 2.6.x' kwargs for `::Logger::LogDevice` messed up with 'binmode'
5
17
 
@@ -11,104 +11,178 @@ 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
19
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
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(:stdout, 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
+ ::Rails.logger.instance_variable_get(:@logdev).dev
42
149
  when :proc
43
- # auto sets related opts for proc device
44
- opts[:payload] = false
150
+ # force overwrite opts
151
+ @ignore_payload = true
45
152
  opts[:nl] = false
46
- opts[:format] ||= :passthrough
153
+ opts[:format] = :passthrough
47
154
 
48
- # set device ONLY if unset in opts
49
- opts[:device] ||= ::RubySmart::SimpleLogger::Devices::ProcDevice.new(opts[:proc])
155
+ ::RubySmart::SimpleLogger::Devices::ProcDevice.new(opts.delete(:proc))
50
156
  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
157
+ # force overwrite opts
158
+ @ignore_payload = true
159
+ opts[:format] = :memory
160
+
161
+ ::RubySmart::SimpleLogger::Devices::MemoryDevice.new
162
+ when Module, String
163
+ # force overwrite opts
164
+ opts[:clr] = false
165
+ _logdev(opts, builtin)
101
166
  else
102
- # forward provided device ONLY if unset in opts
103
- opts[:device] ||= builtin
167
+ _logdev(opts, builtin)
104
168
  end
105
169
  end
106
170
 
107
171
  # resolve the final log-device from provided param
172
+ # @param [Hash] opts
108
173
  # @param [Object] device
109
- # @return [Object]
110
- def _logdev(device)
111
- if device.is_a?(Module)
174
+ # @return [:Logger::LogDevice]
175
+ def _logdev(opts, device = nil)
176
+ device ||= opts.delete(:device)
177
+
178
+ # if existing device is already writeable, simply return it
179
+ return device if device.respond_to?(:write)
180
+
181
+ file_location = nil
182
+
183
+ # resolve the file_location from provided device
184
+ case device
185
+ when Module
112
186
  devstring = device.to_s
113
187
  logfile = (devstring.respond_to?(:underscore) ? devstring.underscore : _underscore(device.to_s)) + '.log'
114
188
  # check for rails
@@ -122,23 +196,36 @@ module RubySmart
122
196
  file_path = File.dirname(file_location)
123
197
  FileUtils.mkdir_p(file_path) unless File.directory?(file_path)
124
198
 
199
+ # the logdev
125
200
  file_location
126
- elsif device.is_a?(String)
127
- device = "log/#{device}" unless device[0] == '/'
201
+ when String
202
+ file_location = (device[0] == '/' ? device : "log/#{device}")
128
203
 
129
204
  # resolve path to create a folder
130
- file_path = File.dirname(device)
205
+ file_path = File.dirname(file_location)
131
206
  FileUtils.mkdir_p(file_path) unless File.directory?(file_path)
132
207
 
133
- device
134
- elsif device.respond_to?(:write)
135
- device
208
+ file_location
136
209
  else
137
- raise "SimpleLogger :: device '#{device}' must respond to 'write'!"
210
+ raise "Unable to build SimpleLogger! The provided device '#{device}' must respond to 'write'!"
211
+ end
212
+
213
+ if GemInfo.match?(RUBY_VERSION, '< 2.7')
214
+ ::Logger::LogDevice.new(file_location,
215
+ shift_age: opts[:shift_age] || 0,
216
+ shift_size: opts[:shift_size] || 1048576,
217
+ shift_period_suffix: opts[:shift_period_suffix])
218
+ else
219
+ ::Logger::LogDevice.new(file_location,
220
+ shift_age: opts[:shift_age] || 0,
221
+ shift_size: opts[:shift_size] || 1048576,
222
+ shift_period_suffix: opts[:shift_period_suffix],
223
+ binmode: opts[:binmode])
138
224
  end
139
225
  end
140
226
 
141
227
  # this is a 1:1 copy of +String#underscore+ @ activesupport gem
228
+ # and only used if activesupport is not available ...
142
229
  def _underscore(camel_cased_word)
143
230
  return camel_cased_word unless /[A-Z-]|::/.match?(camel_cased_word)
144
231
  word = camel_cased_word.to_s.gsub("::", "/")
@@ -150,52 +237,6 @@ module RubySmart
150
237
  word
151
238
  end
152
239
 
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
240
  # returns the +nl+ (new line) flag, depending on the provided options.
200
241
  # recognizes +:nl+ and +:payload+ options.
201
242
  # @param [Hash] opts
@@ -247,8 +288,8 @@ module RubySmart
247
288
  # @param [String] str
248
289
  # @param [String, Symbol, nil] color
249
290
  # @return [String] colored string
250
- def _clr(str, color)
251
- return str unless color && str.respond_to?(color)
291
+ def _clr(str, color = nil)
292
+ return str unless color
252
293
  str.send(color) rescue str
253
294
  end
254
295
 
@@ -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,8 +9,8 @@ module RubySmart
9
9
 
10
10
  module VERSION
11
11
  MAJOR = 1
12
- MINOR = 1
13
- TINY = 1
12
+ MINOR = 2
13
+ TINY = 0
14
14
  PRE = nil
15
15
 
16
16
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
@@ -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.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: 2023-02-07 00:00:00.000000000 Z
11
+ date: 2023-02-16 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