mimi-logger 0.2.5 → 1.0.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
  SHA1:
3
- metadata.gz: ff39280fa18ca6e038a4be72c73e2ef5872c59f1
4
- data.tar.gz: 5a99829862fc9034cc8c55e39cf1e51eedc24d36
3
+ metadata.gz: 4f4073d2c2cedcbb6741dfee2fb68376c3dfcfde
4
+ data.tar.gz: f279d8dd3b2eade0caaf2981bf90886506856a5e
5
5
  SHA512:
6
- metadata.gz: e8e7353ece0c06be660cefdc308c3d58fa76373caf2de99e0f44fbe1a5b51152327e5c9ea8291ac6d7fedfd8bbbcd20e2c36918656ef1a0f29989815381b40cb
7
- data.tar.gz: 10f7a8bfe01ea80fa3bc0a1fbe4e94cc015279fc1f91d7fd5bc88403157f85b3ebfb6521dcd35efa431ab0808f63de09205a87ef844edc12aedfeba43966c9ba
6
+ metadata.gz: d4b7606b4f8f079c275b5345318a9de9b382a0b33ed70be9463c5e843791dbf9fef21841ccbef4204c92439cc73306576736d20c9ffb44a45c348d5c2df95128
7
+ data.tar.gz: '0865e2709e8d6911c8e67f2d181b342170bcb67466bafea817e652d0d57e26f85dfa73a3a58362283641c2d5e4218873a93dc8a845e2e8e6e698e619bcc4415e'
@@ -1,5 +1,5 @@
1
1
  module Mimi
2
2
  class Logger
3
- VERSION = '0.2.5'.freeze
3
+ VERSION = '1.0.0'.freeze
4
4
  end
5
5
  end
data/lib/mimi/logger.rb CHANGED
@@ -22,12 +22,34 @@ module Mimi
22
22
  delegate %i[debug? info? warn? error? fatal? << add log] => :logger_instance
23
23
  delegate %i[context_id context_id= new_context! with_new_context with_preserved_context] => self
24
24
 
25
- default_options(
26
- format: 'json', # 'string' or 'json'
27
- log_context: true,
28
- level: 'info',
29
- cr_character: '↲' # alternative CR: ↵ ↲ ⏎
30
- )
25
+ # Mimi::logger module manifest
26
+ #
27
+ def self.manifest
28
+ {
29
+ logger_format: {
30
+ desc: 'String or JSON',
31
+ default: 'json',
32
+ hidden: true
33
+ },
34
+ logger_context: {
35
+ desc: 'Logger will log context',
36
+ type: :boolean,
37
+ default: true,
38
+ hidden: true
39
+ },
40
+ logger_level: {
41
+ desc: 'Logger severity level threshold',
42
+ default: 'info',
43
+ type: ['debug', 'info', 'warn', 'error', 'fatal']
44
+ },
45
+ logger_cr_character: {
46
+ desc: 'Logger replaces new line with alternative CR character',
47
+ default: '↲', # alternative CR: ↵ ↲ ⏎
48
+ type: :string,
49
+ hidden: true
50
+ }
51
+ }
52
+ end
31
53
 
32
54
  # Creates a new Logger instance
33
55
  #
@@ -49,9 +71,12 @@ module Mimi
49
71
  opts ||= {}
50
72
  raise ArgumentError, '(io, opts) are expected as parameters' unless args.empty?
51
73
 
52
- @options = self.class.module_options.deep_merge(opts)
74
+ # module configured?
75
+ self.class.configure() if self.class.options.empty?
76
+
77
+ @options = self.class.options.deep_merge(opts)
53
78
  @logger_instance = ::Logger.new(io)
54
- @logger_instance.level = self.class.level_from_any(options[:level])
79
+ @logger_instance.level = self.class.level_from_any(options[:logger_level])
55
80
  io.sync = true if io.respond_to?(:sync=)
56
81
  @logger_instance.formatter = self.class.formatter(options)
57
82
  end
@@ -138,14 +163,14 @@ module Mimi
138
163
  # @return [Proc]
139
164
  # @private
140
165
  #
141
- def self.formatter(options)
142
- case options[:format].to_s
166
+ def self.formatter(local_options)
167
+ case local_options[:logger_format].to_s
143
168
  when 'json'
144
- formatter_json(options)
169
+ formatter_json(local_options)
145
170
  when 'string'
146
- formatter_string(options)
171
+ formatter_string(local_options)
147
172
  else
148
- raise "Invalid format specified for Mimi::Logger: '#{module_options[:format]}'"
173
+ raise "Invalid format specified for Mimi::Logger: '#{local_options[:logger_format]}'"
149
174
  end
150
175
  end
151
176
 
@@ -155,10 +180,10 @@ module Mimi
155
180
  # @return [Proc]
156
181
  # @private
157
182
  #
158
- def self.formatter_json(options)
183
+ def self.formatter_json(local_options)
159
184
  proc do |severity, _datetime, _progname, message|
160
185
  h = formatter_message_args_to_hash(message)
161
- h[:c] = context_id if options[:log_context]
186
+ h[:c] = context_id if local_options[:logger_context]
162
187
  h[:s] = severity.to_s[0]
163
188
  JSON.dump(h) + "\n"
164
189
  end
@@ -170,13 +195,13 @@ module Mimi
170
195
  # @return [Proc]
171
196
  # @private
172
197
  #
173
- def self.formatter_string(options)
198
+ def self.formatter_string(local_options)
174
199
  proc do |severity, _datetime, _progname, message|
175
200
  h = formatter_message_args_to_hash(message)
176
201
  parts = []
177
202
  parts << severity.to_s[0]
178
- parts << context_id if options[:log_context]
179
- parts << h[:m].to_s.tr("\n", options[:cr_character])
203
+ parts << context_id if local_options[:logger_context]
204
+ parts << h[:m].to_s.tr("\n", local_options[:logger_cr_character])
180
205
  parts << '...' unless h.except(:m).empty?
181
206
  parts.join(', ') + "\n"
182
207
  end
@@ -290,16 +315,6 @@ module Mimi
290
315
  yield
291
316
  end
292
317
  end
293
-
294
- # @private
295
- def self.module_manifest
296
- {
297
- log_level: {
298
- desc: 'Logging level (any of the "debug", "info", "warn", "error", "fatal")',
299
- default: 'info'
300
- }
301
- }
302
- end
303
318
  end # class Logger
304
319
  end # module Mimi
305
320
 
data/mimi-logger.gemspec CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
27
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
28
28
  spec.require_paths = ['lib']
29
29
 
30
- spec.add_dependency 'mimi-core'
30
+ spec.add_dependency 'mimi-core', '~> 1.0'
31
31
 
32
32
  spec.add_development_dependency 'bundler', '~> 1.11'
33
33
  spec.add_development_dependency 'rake', '~> 10.0'
metadata CHANGED
@@ -1,29 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mimi-logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.5
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Alex Kukushkin
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-05-23 00:00:00.000000000 Z
11
+ date: 2019-05-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: mimi-core
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '1.0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '1.0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: bundler
29
29
  requirement: !ruby/object:Gem::Requirement
@@ -123,7 +123,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
123
123
  version: '0'
124
124
  requirements: []
125
125
  rubyforge_project:
126
- rubygems_version: 2.6.14.1
126
+ rubygems_version: 2.6.14.4
127
127
  signing_key:
128
128
  specification_version: 4
129
129
  summary: A pre-configured logger for microservice applications