ruby_smart-simple_logger 1.2.0 → 1.2.2

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: a47086748b62315efd5a4497e118bbb8a537cb153099cefa99e9432a8ed14ecb
4
- data.tar.gz: 9f74e2177dfd4fb008fb8b203d282217a37846c724b4e2b0bfa55ae982ea83ef
3
+ metadata.gz: f93f509aad065f314393b0b7f630694091fb06c967bc20ad1fe4e0b7683f843b
4
+ data.tar.gz: 9d5a325fac9bc01ad330cec1c1c31a9bc3f5602e1934893b04ab5f3baed22ac0
5
5
  SHA512:
6
- metadata.gz: 50d2cb4beda62d0c4189c22eb201ae8cc95e1cf6d9e0f037522f58c27ce3ddf34a000fba9156a71b662b223313fe2cdd4d5589916094cbe19b71393220e62464
7
- data.tar.gz: 723da7c50cc2d87ea2c8de011c0f54d743c32c5abf99da5441a5cf6a6cec7657ec4dd35de3d67ab6d3cc9ed8b95db01c0ef702a20a6d33b8a25d1f1ba7ab34dc
6
+ metadata.gz: 5b4b91d4c70cd0e373af89191b9147739a55443e851ffdc8751e3853d833e04f59cd9aa6d125a60c752e924686a190d8bd492560860e91d18749af48adc210d4
7
+ data.tar.gz: 5cb89dd0a2cf9b77f3ce2cbc4bcf7c9f8ee218fb9030a16c9bba0259ac5ca16bf82fcdffef2602533b567b2591d94f672662a46e3562b8a1fdee398980137718
data/docs/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # RubySmart::SimpleLogger - CHANGELOG
2
2
 
3
+ ## [1.2.2] - 2023-03-15
4
+ * **[ref]** simplify device-generation for builtins
5
+ * **[fix]** `ActionView::Helpers::DateHelper` require, which breaks rails loading process in some cases
6
+
7
+ ## [1.2.1] - 2023-02-17
8
+ * **[fix]** 'rails'-related builtins
9
+ * **[fix]** `::RubySmart::SimpleLogger::Devices::MultiDevice` register `MultiDevice` instead of nested devices
10
+
3
11
  ## [1.2.0] - 2023-02-16
4
12
  * **[add]** multi-'builtins' support
5
13
  * **[ref]** `Logger` initialization - now supports to provide multiple builtins
@@ -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
@@ -61,36 +61,30 @@ module RubySmart
61
61
  # check for already existing +device+
62
62
  return if opts[:device]
63
63
 
64
- # remove builtin key from opts
65
- builtin = opts.delete(:builtin)
64
+ # remove builtin key from opts and force an array
65
+ builtins = Array(opts.delete(:builtin))
66
66
 
67
- # retransform array into single value
68
- builtin = builtin[0] if builtin.is_a?(Array) && builtin.length < 2
67
+ # expand builtins with stdout
68
+ builtins << :stdout if opts.delete(:stdout)
69
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
70
+ # expand builtins with memory
71
+ builtins << :memory if opts.delete(:memory)
75
72
 
76
- if opts.delete(:memory)
77
- builtin = [builtin] unless builtin.is_a?(Array)
78
- builtin << :memory
79
- end
73
+ builtins.uniq!
80
74
 
81
- # determinate builtin - first check to create +MultiDevice+.
82
- if builtin.is_a?(Array)
75
+ # don't create multi-device for a single (or +nil+) builtin
76
+ if builtins.length < 2
77
+ opts[:device] = _resolve_device(builtins[0], opts)
78
+ else
83
79
  opts[:device] = ::RubySmart::SimpleLogger::Devices::MultiDevice.new
84
- builtin.uniq.each do |key|
80
+ builtins.each do |builtin|
85
81
  # IMPORTANT: dup, original hash to prevent reference manipulation (on the TOP-level, only)
86
82
  builtin_opts = opts.dup
87
- opts[:device].register(_resolve_device(key, builtin_opts), _resolve_formatter(builtin_opts))
83
+ opts[:device].register(_resolve_device(builtin, builtin_opts), _resolve_formatter(builtin_opts))
88
84
  end
89
85
 
90
86
  # force 'passthrough', as format, since this is required for multi-devices
91
87
  opts[:format] = :passthrough
92
- else
93
- opts[:device] = _resolve_device(builtin, opts)
94
88
  end
95
89
 
96
90
  # prevent to return any data
@@ -136,7 +130,7 @@ module RubySmart
136
130
  if ::ThreadInfo.stdout?
137
131
  _resolve_device(:stdout, opts)
138
132
  elsif ::ThreadInfo.rails? && ::Rails.logger
139
- _resolve_device(:stdout, opts)
133
+ _resolve_device(:rails, opts)
140
134
  else
141
135
  _resolve_device(:memory, opts)
142
136
  end
@@ -145,7 +139,16 @@ module RubySmart
145
139
  when :stderr
146
140
  STDERR
147
141
  when :rails
148
- ::Rails.logger.instance_variable_get(:@logdev).dev
142
+ raise "Unable to build SimpleLogger with 'rails' builtin for not initialized rails application!" unless ThreadInfo.rails?
143
+
144
+ # special check for rails-with-console (IRB -> STDOUT) combination - mostly in combination with +Debase+.
145
+ if ThreadInfo.console? && ::Rails.logger.instance_variable_get(:@logdev).dev != STDOUT
146
+ ::RubySmart::SimpleLogger::Devices::MultiDevice
147
+ .register(_resolve_device(:stdout, opts))
148
+ .register(::Rails.logger.instance_variable_get(:@logdev).dev)
149
+ else
150
+ ::Rails.logger.instance_variable_get(:@logdev).dev
151
+ end
149
152
  when :proc
150
153
  # force overwrite opts
151
154
  @ignore_payload = true
@@ -10,7 +10,7 @@ module RubySmart
10
10
  module VERSION
11
11
  MAJOR = 1
12
12
  MINOR = 2
13
- TINY = 0
13
+ TINY = 2
14
14
  PRE = nil
15
15
 
16
16
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join(".")
@@ -17,9 +17,8 @@ module RubySmart
17
17
  end
18
18
 
19
19
  # load date extensions for logger
20
- if GemInfo.loaded?('activesupport') && GemInfo.installed?('actionview')
21
- ActiveSupport.on_load(:active_record) do
22
- require('action_view/helpers/date_helper')
23
- RubySmart::SimpleLogger::Logger.include(ActionView::Helpers::DateHelper)
24
- end
20
+ # since 'actionview' is loaded in different ways, we only can check for +installed?+ here...
21
+ if GemInfo.installed?('actionview')
22
+ # IMPORTANT: any require will break the loading process
23
+ RubySmart::SimpleLogger::Logger.include(ActionView::Helpers::DateHelper) unless RubySmart::SimpleLogger::Logger.included_modules.include?(ActionView::Helpers::DateHelper)
25
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.2.0
4
+ version: 1.2.2
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-16 00:00:00.000000000 Z
11
+ date: 2023-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: ruby_smart-support