ruby_smart-simple_logger 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +23 -12
- data/docs/CHANGELOG.md +15 -0
- data/lib/ruby_smart/simple_logger/extensions/helper.rb +174 -127
- data/lib/ruby_smart/simple_logger/extensions/logs.rb +2 -2
- data/lib/ruby_smart/simple_logger/gem_version.rb +1 -1
- data/lib/ruby_smart/simple_logger/klass_logger.rb +3 -4
- data/lib/ruby_smart/simple_logger/logger.rb +21 -21
- data/lib/ruby_smart/simple_logger/scenes.rb +9 -9
- data/lib/ruby_smart/simple_logger.rb +1 -1
- data/lib/{debugger.rb → ruby_smart-debugger.rb} +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a47086748b62315efd5a4497e118bbb8a537cb153099cefa99e9432a8ed14ecb
|
4
|
+
data.tar.gz: 9f74e2177dfd4fb008fb8b203d282217a37846c724b4e2b0bfa55ae982ea83ef
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
-
|
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
|
751
|
+
# ╔ START :: Process Alpha
|
741
752
|
# ╟ find files
|
742
753
|
# ╟ found 34 files
|
743
|
-
# ║ ┌ START
|
754
|
+
# ║ ┌ START :: extracting ...
|
744
755
|
# ║ ├ 10% done
|
745
756
|
# ║ ├ 20% done
|
746
757
|
# ║ ├ 100% done
|
747
|
-
# ║ └ END
|
748
|
-
# ║ ┌ START
|
758
|
+
# ║ └ END [SUCCESS] (duration: 0.000267545)
|
759
|
+
# ║ ┌ START :: transforming ...
|
749
760
|
# ║ ├ bad memory
|
750
761
|
# ║ ├ rolling back
|
751
|
-
# ║ └ END
|
752
|
-
# ╚ END
|
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,20 @@
|
|
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
|
+
|
15
|
+
## [1.1.1] - 2023-02-07
|
16
|
+
* **[fix]** 'ruby 2.6.x' kwargs for `::Logger::LogDevice` messed up with 'binmode'
|
17
|
+
|
3
18
|
## [1.1.0] - 2023-02-07
|
4
19
|
* **[add]** `#processed` method for logger
|
5
20
|
* **[ref]** `Debugger` to enforce a 'DEBUG' severity
|
@@ -11,98 +11,178 @@ module RubySmart
|
|
11
11
|
|
12
12
|
private
|
13
13
|
|
14
|
-
#
|
14
|
+
# set / overwrite default opts
|
15
15
|
# @param [Hash] opts
|
16
|
-
|
17
|
-
|
18
|
-
|
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
|
-
|
137
|
+
_resolve_device(:stdout, opts)
|
25
138
|
elsif ::ThreadInfo.rails? && ::Rails.logger
|
26
|
-
|
139
|
+
_resolve_device(:stdout, opts)
|
27
140
|
else
|
28
|
-
|
141
|
+
_resolve_device(:memory, opts)
|
29
142
|
end
|
30
143
|
when :stdout
|
31
|
-
|
32
|
-
opts[:device] ||= STDOUT
|
33
|
-
# colorize output
|
34
|
-
opts[:clr] = true if opts[:clr].nil?
|
144
|
+
STDOUT
|
35
145
|
when :stderr
|
36
|
-
|
37
|
-
# colorize output
|
38
|
-
opts[:clr] = true if opts[:clr].nil?
|
146
|
+
STDERR
|
39
147
|
when :rails
|
40
|
-
|
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
|
-
#
|
44
|
-
|
150
|
+
# force overwrite opts
|
151
|
+
@ignore_payload = true
|
45
152
|
opts[:nl] = false
|
46
|
-
opts[:format]
|
153
|
+
opts[:format] = :passthrough
|
47
154
|
|
48
|
-
|
49
|
-
opts[:device] ||= ::RubySmart::SimpleLogger::Devices::ProcDevice.new(opts[:proc])
|
155
|
+
::RubySmart::SimpleLogger::Devices::ProcDevice.new(opts.delete(:proc))
|
50
156
|
when :memory
|
51
|
-
#
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
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
|
-
::Logger::LogDevice.new(_logdev(builtin),
|
85
|
-
shift_age: opts[:shift_age] || 0,
|
86
|
-
shift_size: opts[:shift_size] || 1048576,
|
87
|
-
shift_period_suffix: opts[:shift_period_suffix],
|
88
|
-
binmode: opts[:binmode]),
|
89
|
-
::RubySmart::SimpleLogger::Formatter.new(format: device_format, nl: _nl(opts), clr: false)
|
90
|
-
)
|
91
|
-
.register(STDOUT, ::RubySmart::SimpleLogger::Formatter.new(format: device_format, nl: _nl(opts), clr: opts[:clr]))
|
92
|
-
else
|
93
|
-
builtin
|
94
|
-
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)
|
95
166
|
else
|
96
|
-
|
97
|
-
opts[:device] ||= builtin
|
167
|
+
_logdev(opts, builtin)
|
98
168
|
end
|
99
169
|
end
|
100
170
|
|
101
171
|
# resolve the final log-device from provided param
|
172
|
+
# @param [Hash] opts
|
102
173
|
# @param [Object] device
|
103
|
-
# @return [
|
104
|
-
def _logdev(device)
|
105
|
-
|
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
|
106
186
|
devstring = device.to_s
|
107
187
|
logfile = (devstring.respond_to?(:underscore) ? devstring.underscore : _underscore(device.to_s)) + '.log'
|
108
188
|
# check for rails
|
@@ -116,23 +196,36 @@ module RubySmart
|
|
116
196
|
file_path = File.dirname(file_location)
|
117
197
|
FileUtils.mkdir_p(file_path) unless File.directory?(file_path)
|
118
198
|
|
199
|
+
# the logdev
|
119
200
|
file_location
|
120
|
-
|
121
|
-
|
201
|
+
when String
|
202
|
+
file_location = (device[0] == '/' ? device : "log/#{device}")
|
122
203
|
|
123
204
|
# resolve path to create a folder
|
124
|
-
file_path = File.dirname(
|
205
|
+
file_path = File.dirname(file_location)
|
125
206
|
FileUtils.mkdir_p(file_path) unless File.directory?(file_path)
|
126
207
|
|
127
|
-
|
128
|
-
elsif device.respond_to?(:write)
|
129
|
-
device
|
208
|
+
file_location
|
130
209
|
else
|
131
|
-
raise "SimpleLogger
|
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])
|
132
224
|
end
|
133
225
|
end
|
134
226
|
|
135
227
|
# this is a 1:1 copy of +String#underscore+ @ activesupport gem
|
228
|
+
# and only used if activesupport is not available ...
|
136
229
|
def _underscore(camel_cased_word)
|
137
230
|
return camel_cased_word unless /[A-Z-]|::/.match?(camel_cased_word)
|
138
231
|
word = camel_cased_word.to_s.gsub("::", "/")
|
@@ -144,52 +237,6 @@ module RubySmart
|
|
144
237
|
word
|
145
238
|
end
|
146
239
|
|
147
|
-
# build log-device & options on initialize
|
148
|
-
# @param [Hash] opts
|
149
|
-
# @return [Array<logdev,opts>] logdev, opts
|
150
|
-
def _init_opts(opts)
|
151
|
-
# clean & rewrite opts (especially device) to a real logdev
|
152
|
-
_opts_builtin(opts)
|
153
|
-
|
154
|
-
# set mask from options
|
155
|
-
self.mask(opts[:mask]) if opts[:mask]
|
156
|
-
|
157
|
-
# disable mask color if explicit disabled
|
158
|
-
self.mask(clr: false) if opts[:clr] == false
|
159
|
-
|
160
|
-
# reduce mask-size to window size
|
161
|
-
if ::ThreadInfo.windowed? && ::ThreadInfo.winsize[1] < self.mask[:length]
|
162
|
-
self.mask(length: ::ThreadInfo.winsize[1])
|
163
|
-
end
|
164
|
-
|
165
|
-
# initialize a default rails-dependent output
|
166
|
-
if ::ThreadInfo.rails?
|
167
|
-
opts[:level] ||= (::Rails.env.production? ? :info : :debug)
|
168
|
-
end
|
169
|
-
|
170
|
-
# clean & rewrite level (possible symbols) to real level
|
171
|
-
opts[:level] = _level(opts[:level] || :debug)
|
172
|
-
|
173
|
-
# clean & rewrite nl
|
174
|
-
opts[:nl] = _nl(opts)
|
175
|
-
|
176
|
-
# rewrite format
|
177
|
-
opts[:format] ||= :plain
|
178
|
-
|
179
|
-
# provide custom formatter and forward special opts (format, nl, clr)
|
180
|
-
opts[:formatter] ||= ::RubySmart::SimpleLogger::Formatter.new(opts)
|
181
|
-
|
182
|
-
# ignore payload and send data directly to the logdev
|
183
|
-
@ignore_payload = true if opts[:payload].is_a?(FalseClass)
|
184
|
-
|
185
|
-
# set the inspector to be used for data inspection.
|
186
|
-
# 'disable' inspector, if false was provided - which simply results in +#to_s+
|
187
|
-
@inspector = (opts[:inspect] === false) ? :to_s : opts[:inspector]
|
188
|
-
|
189
|
-
# simple return opts
|
190
|
-
opts
|
191
|
-
end
|
192
|
-
|
193
240
|
# returns the +nl+ (new line) flag, depending on the provided options.
|
194
241
|
# recognizes +:nl+ and +:payload+ options.
|
195
242
|
# @param [Hash] opts
|
@@ -241,8 +288,8 @@ module RubySmart
|
|
241
288
|
# @param [String] str
|
242
289
|
# @param [String, Symbol, nil] color
|
243
290
|
# @return [String] colored string
|
244
|
-
def _clr(str, color)
|
245
|
-
return str unless color
|
291
|
+
def _clr(str, color = nil)
|
292
|
+
return str unless color
|
246
293
|
str.send(color) rescue str
|
247
294
|
end
|
248
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.
|
11
|
-
logdev.
|
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, ...)
|
@@ -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
|
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
|
-
#
|
44
|
-
#
|
45
|
-
# @param [
|
46
|
-
# @option
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
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
|
-
|
55
|
-
|
56
|
-
|
52
|
+
# enhance options with device & formatter
|
53
|
+
_opts_device!(opts)
|
54
|
+
_opts_formatter!(opts)
|
57
55
|
|
58
|
-
# initialize provided opts
|
59
|
-
|
56
|
+
# initialize & set defaults by provided opts
|
57
|
+
_opts_init!(opts)
|
60
58
|
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
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 @
|
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: :
|
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
|
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
|
-
|
307
|
+
'SUCCESS'
|
308
308
|
when false
|
309
|
-
|
309
|
+
'FAILED'
|
310
310
|
else
|
311
|
-
|
311
|
+
name
|
312
312
|
end
|
313
313
|
|
314
|
-
self.log("#{end_str} #{(timer_key ? "(duration: #{self.timer(:clear, timer_key, :
|
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(:
|
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
|
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.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-
|
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
|
@@ -161,7 +161,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
161
161
|
- !ruby/object:Gem::Version
|
162
162
|
version: '0'
|
163
163
|
requirements: []
|
164
|
-
rubygems_version: 3.3.
|
164
|
+
rubygems_version: 3.3.26
|
165
165
|
signing_key:
|
166
166
|
specification_version: 4
|
167
167
|
summary: A simple, multifunctional logging library for Ruby.
|