lenjador 2.0.1 → 2.1.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: e6359342424a40cb441683e064b1612f3b0f5713d9d0fec3e47b962c6e454c4f
4
- data.tar.gz: 4e4f17a2c36d7878e62d8e69b594233e38af42bb389baa45e18d1aa59a33ea97
3
+ metadata.gz: 5d96edbeff69ee13444e45a5924d8fedd4907725831f9ce62fd2f3280b48b244
4
+ data.tar.gz: b7e501d6a7dba6b7461df12e72530796900a4241700dd676c48d6e6f8341e0b2
5
5
  SHA512:
6
- metadata.gz: 3ae2521b86d68b591a786241dab8b45316a8c2a5dcafd2c7ef98ad9f13c13c1141f4e15c4cef1b6fc8f1b346d217e4a96a2f7f97431bc6448a90a70143345d7b
7
- data.tar.gz: e04916f56b096f9236c7331ac3ccbbc03f4e9dae68eff047fa252be928bf09f832d61d4e321bfb4aa9234bfceebf65ef452892ff90390cf7debbfb76711826f6
6
+ metadata.gz: b1142e4a26fb13f3ba2d880de8c3b58e18eacc77de055d36b10c3a9783c6c1d597a50aab94f1611a43fc17f8490f6598049da6f5d4c9ed73af77be2fa5ccb26e
7
+ data.tar.gz: 6f6d29354c80eae57485fc2f3fa5f6e0643aad692763957ab43c8ba3041a8f5d9cbba6fb3e9453a121c6634d5e7e776d82df0286a966b97613d03c437b602827
data/.rubocop.yml CHANGED
@@ -1,6 +1,9 @@
1
1
  inherit_gem:
2
2
  rubocop-salemove: config/default.yml
3
3
 
4
+ AllCops:
5
+ TargetRubyVersion: 2.4
6
+
4
7
  Style/FrozenStringLiteralComment:
5
8
  Enabled: yes
6
9
  EnforcedStyle: always
data/.travis.yml CHANGED
@@ -3,4 +3,3 @@ rvm:
3
3
  - 2.4
4
4
  - 2.5
5
5
  - 2.7
6
- - jruby
data/lenjador.gemspec CHANGED
@@ -4,13 +4,14 @@ lib = File.expand_path('lib', __dir__)
4
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
5
 
6
6
  Gem::Specification.new do |gem|
7
- gem.name = RUBY_PLATFORM =~ /java/ ? 'lenjador-jruby' : 'lenjador'
8
- gem.version = '2.0.1'
7
+ gem.name = 'lenjador'
8
+ gem.version = '2.1.0'
9
9
  gem.authors = ['Salemove']
10
10
  gem.email = ['support@salemove.com']
11
11
  gem.description = "It's lenjadoric"
12
12
  gem.summary = 'What description said'
13
13
  gem.license = 'MIT'
14
+ gem.required_ruby_version = '>= 2.4'
14
15
 
15
16
  gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
16
17
  gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
@@ -18,13 +19,7 @@ Gem::Specification.new do |gem|
18
19
  gem.require_paths = ['lib']
19
20
 
20
21
  gem.add_dependency 'lru_redux'
21
-
22
- if RUBY_PLATFORM =~ /java/
23
- gem.add_dependency 'jrjackson'
24
- else
25
- gem.add_dependency 'oj', '~> 3.6'
26
- gem.add_development_dependency 'ruby-prof'
27
- end
22
+ gem.add_dependency 'oj', '~> 3.6'
28
23
 
29
24
  gem.add_development_dependency 'benchmark-ips'
30
25
  gem.add_development_dependency 'bundler'
@@ -32,4 +27,5 @@ Gem::Specification.new do |gem|
32
27
  gem.add_development_dependency 'rake'
33
28
  gem.add_development_dependency 'rspec'
34
29
  gem.add_development_dependency 'rubocop-salemove'
30
+ gem.add_development_dependency 'ruby-prof'
35
31
  end
data/lib/lenjador.rb CHANGED
@@ -58,6 +58,12 @@ class Lenjador
58
58
 
59
59
  def fatal?; @level <= Severity::FATAL; end
60
60
 
61
+ def level=(new_level)
62
+ raise ArgumentError, "invalid log level: #{new_level}" unless new_level.is_a?(Integer)
63
+
64
+ @level = new_level
65
+ end
66
+
61
67
  private
62
68
 
63
69
  def log(level, *args, &block)
@@ -8,7 +8,7 @@ class Lenjador
8
8
  attr_reader :logger
9
9
 
10
10
  def initialize(_service_name)
11
- @logger = Logger.new(STDOUT)
11
+ @logger = Logger.new($stdout)
12
12
  end
13
13
 
14
14
  def log(level, metadata = {})
@@ -22,11 +22,11 @@ class Lenjador
22
22
  end
23
23
  elsif RUBY_ENGINE == 'jruby'
24
24
  def print_line(str)
25
- @mutex.synchronize { $stdout.write(str + "\n") }
25
+ @mutex.synchronize { $stdout.write("#{str}\n") }
26
26
  end
27
27
  else
28
28
  def print_line(str)
29
- $stdout.write(str + "\n")
29
+ $stdout.write("#{str}\n")
30
30
  end
31
31
  end
32
32
  end
@@ -20,7 +20,8 @@ class Lenjador
20
20
  end
21
21
 
22
22
  def process(data)
23
- if data.is_a? Hash
23
+ case data
24
+ when Hash
24
25
  data.inject({}) do |mem, (key, val)|
25
26
  if (field = @fields_to_process[key.to_s])
26
27
  send(action_method(field[:action]), mem, key, val)
@@ -28,7 +29,7 @@ class Lenjador
28
29
  mem.merge(key => process(val))
29
30
  end
30
31
  end
31
- elsif data.is_a? Array
32
+ when Array
32
33
  data.inject([]) do |mem, val|
33
34
  mem + [process(val)]
34
35
  end
@@ -1,11 +1,17 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'time'
4
+ require 'oj'
4
5
 
5
6
  class Lenjador
6
7
  module Utils
7
8
  DECIMAL_FRACTION_OF_SECOND = 3
8
9
  NO_TRACE_INFORMATION = {}.freeze
10
+ DUMP_OPTIONS = {
11
+ mode: :custom,
12
+ time_format: :xmlschema,
13
+ second_precision: 3
14
+ }.freeze
9
15
 
10
16
  # Build logstash json compatible event
11
17
  #
@@ -43,28 +49,8 @@ class Lenjador
43
49
  end
44
50
  private_class_method :overwritable_params
45
51
 
46
- if RUBY_PLATFORM =~ /java/
47
- require 'jrjackson'
48
-
49
- DUMP_OPTIONS = {
50
- timezone: 'utc',
51
- date_format: "YYYY-MM-dd'T'HH:mm:ss.SSSX"
52
- }.freeze
53
-
54
- def self.generate_json(obj)
55
- JrJackson::Json.dump(obj, DUMP_OPTIONS)
56
- end
57
- else
58
- require 'oj'
59
- DUMP_OPTIONS = {
60
- mode: :custom,
61
- time_format: :xmlschema,
62
- second_precision: 3
63
- }.freeze
64
-
65
- def self.generate_json(obj)
66
- Oj.dump(obj, DUMP_OPTIONS)
67
- end
52
+ def self.generate_json(obj)
53
+ Oj.dump(obj, DUMP_OPTIONS)
68
54
  end
69
55
 
70
56
  def self.underscore(input)
@@ -16,7 +16,7 @@ describe Lenjador::Adapters::StdoutJsonAdapter do
16
16
  end
17
17
  end
18
18
 
19
- describe '#log' do
19
+ describe '#log' do # rubocop:disable RSpec/MultipleMemoizedHelpers
20
20
  let(:adapter) { described_class.new(service_name) }
21
21
  let(:metadata) { {x: 'y'} }
22
22
  let(:event) { {a: 'b', x: 'y'} }
@@ -34,7 +34,7 @@ describe Lenjador::Adapters::StdoutJsonAdapter do
34
34
 
35
35
  it 'sends serialized event to $stdout' do
36
36
  adapter.log(info, metadata)
37
- expect(output).to eq serialized_event + "\n"
37
+ expect(output).to eq("#{serialized_event}\n")
38
38
  end
39
39
  end
40
40
 
@@ -46,7 +46,7 @@ describe Lenjador::Utils do
46
46
  end
47
47
  end
48
48
 
49
- context 'when OpenTracing is defined' do
49
+ context 'when OpenTracing is defined' do # rubocop:disable RSpec/MultipleMemoizedHelpers
50
50
  let(:trace_id) { 'trace-id' }
51
51
  let(:span_id) { 'span-id' }
52
52
 
@@ -128,4 +128,23 @@ describe Lenjador do
128
128
  end
129
129
  end
130
130
  end
131
+
132
+ it 'allows changing log level on existing instance' do
133
+ logger = described_class.build('test_service', level: 'info')
134
+
135
+ logger.level = ::Logger::DEBUG
136
+ expect(logger.debug?).to eq(true)
137
+
138
+ logger.level = ::Logger::INFO
139
+ expect(logger.debug?).to eq(false)
140
+ expect(logger.info?).to eq(true)
141
+
142
+ logger.level = ::Logger::WARN
143
+ expect(logger.info?).to eq(false)
144
+ expect(logger.warn?).to eq(true)
145
+
146
+ logger.level = ::Logger::ERROR
147
+ expect(logger.warn?).to eq(false)
148
+ expect(logger.error?).to eq(true)
149
+ end
131
150
  end
data/spec/spec_helper.rb CHANGED
@@ -5,7 +5,7 @@ Bundler.setup
5
5
 
6
6
  require 'lenjador'
7
7
 
8
- Dir[File.dirname(__FILE__) + '/support/*.rb'].sort.each { |f| require f }
8
+ Dir["#{File.dirname(__FILE__)}/support/*.rb"].sort.each { |f| require f }
9
9
 
10
10
  RSpec.configure do |config|
11
11
  config.run_all_when_everything_filtered = true
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: lenjador
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Salemove
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-04-28 00:00:00.000000000 Z
11
+ date: 2021-05-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: lru_redux
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3.6'
41
41
  - !ruby/object:Gem::Dependency
42
- name: ruby-prof
42
+ name: benchmark-ips
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - ">="
@@ -53,7 +53,7 @@ dependencies:
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
- name: benchmark-ips
56
+ name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
59
  - - ">="
@@ -67,7 +67,7 @@ dependencies:
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
- name: bundler
70
+ name: pry
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
73
  - - ">="
@@ -81,7 +81,7 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: pry
84
+ name: rake
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - ">="
@@ -95,7 +95,7 @@ dependencies:
95
95
  - !ruby/object:Gem::Version
96
96
  version: '0'
97
97
  - !ruby/object:Gem::Dependency
98
- name: rake
98
+ name: rspec
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
101
  - - ">="
@@ -109,7 +109,7 @@ dependencies:
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  - !ruby/object:Gem::Dependency
112
- name: rspec
112
+ name: rubocop-salemove
113
113
  requirement: !ruby/object:Gem::Requirement
114
114
  requirements:
115
115
  - - ">="
@@ -123,7 +123,7 @@ dependencies:
123
123
  - !ruby/object:Gem::Version
124
124
  version: '0'
125
125
  - !ruby/object:Gem::Dependency
126
- name: rubocop-salemove
126
+ name: ruby-prof
127
127
  requirement: !ruby/object:Gem::Requirement
128
128
  requirements:
129
129
  - - ">="
@@ -188,7 +188,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
188
188
  requirements:
189
189
  - - ">="
190
190
  - !ruby/object:Gem::Version
191
- version: '0'
191
+ version: '2.4'
192
192
  required_rubygems_version: !ruby/object:Gem::Requirement
193
193
  requirements:
194
194
  - - ">="