lenjador 1.2.1 → 1.3.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: 0b22b9348f98f915eaa67dec7cbbe762d09f86dc
4
- data.tar.gz: 2e22ff6de0251d2e007b83e626e14c20d860b281
3
+ metadata.gz: 10e0eaa5dd3548c6bfc7ff8c980e7e500ee4d297
4
+ data.tar.gz: c2dd081c02374b3144f3a7c77494c3f19b7ef464
5
5
  SHA512:
6
- metadata.gz: e48ff7741f76c07e5dd00e910e32cd6013ee4ff6854ccfc29bf4dc249e54635500c4ff5fedd51ac7394a643baa4a6e1a60269b41b9c5fb2006110fefe45f13af
7
- data.tar.gz: 0cd79d4f685890c86d4c0c182f256f35c0dbe48a95b77a548193cbec05f21a8df5ce551c1fd77fe5a9a751a5a9491b04c24e78392c9bb7ae7fa92ea2f272ae29
6
+ metadata.gz: d3766944053913a9345b4a8415f9de802c93de119affebd85fe43fe8696047ee656e586d84c6e0bf45cacdbcb376fafd443bea60c92728265f53c5bfa457daaa
7
+ data.tar.gz: e87536d2ccc0abf5176f474f782458877832b47335c30ae0d6f714bae688b10e934627446dc9d1a879a488c5e023585db1ba928575502ce2c962e9d19832c8cb
@@ -0,0 +1,38 @@
1
+ inherit_gem:
2
+ rubocop-salemove: config/default.yml
3
+
4
+ Style/FrozenStringLiteralComment:
5
+ Enabled: yes
6
+ EnforcedStyle: always
7
+ Include:
8
+ - 'lib/**/*'
9
+
10
+ Metrics/MethodLength:
11
+ Enabled: no
12
+
13
+ Style/GuardClause:
14
+ Enabled: no
15
+
16
+ RSpec/VerifiedDoubles:
17
+ Enabled: no
18
+
19
+ Metrics/BlockLength:
20
+ Enabled: no
21
+
22
+ RSpec/MessageSpies:
23
+ Enabled: no
24
+
25
+ RSpec/ExpectOutput:
26
+ Enabled: no
27
+
28
+ RSpec/ExampleLength:
29
+ Enabled: no
30
+
31
+ RSpec/MultipleExpectations:
32
+ Enabled: no
33
+
34
+ Style/SafeNavigation:
35
+ Enabled: no
36
+
37
+ Performance/RegexpMatch:
38
+ Enabled: no
@@ -1,6 +1,5 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.2
4
3
  - 2.3
5
4
  - 2.4
6
5
  - 2.5
data/Gemfile CHANGED
@@ -1,8 +1,3 @@
1
- source "https://rubygems.org"
2
-
3
- group :test, :development do
4
- gem 'pry'
5
- gem 'rspec'
6
- end
1
+ source 'https://rubygems.org'
7
2
 
8
3
  gemspec
data/Rakefile CHANGED
@@ -1,7 +1,9 @@
1
- require "bundler/gem_tasks"
1
+ require 'bundler/gem_tasks'
2
+ require 'rubocop/rake_task'
3
+ require 'rspec/core/rake_task'
2
4
 
3
- require "rspec/core/rake_task"
4
5
  RSpec::Core::RakeTask.new(:spec)
5
6
 
6
- task ci: :spec
7
- task default: :spec
7
+ RuboCop::RakeTask.new(:rubocop)
8
+
9
+ task default: %i[rubocop spec]
@@ -21,20 +21,20 @@ pointers = %w[
21
21
  end
22
22
 
23
23
  x.report("Flat hash whitelisting (action=#{action})") do
24
- preprocessor.process(flat_hash: { scalar: 'value', array: [1, 2], hash: {} })
24
+ preprocessor.process(flat_hash: {scalar: 'value', array: [1, 2], hash: {}})
25
25
  end
26
26
 
27
27
  x.report("Nested hash whitelisting (action=#{action})") do
28
28
  preprocessor.process(
29
29
  nested_hash: {
30
30
  next_level_hash: {
31
- deep_hash: { scalar: 'value', array: [1, 2] }
31
+ deep_hash: {scalar: 'value', array: [1, 2]}
32
32
  },
33
33
  next_level_hash2: {
34
- deep_hash: { scalar: 'value', array: [1, 2] }
34
+ deep_hash: {scalar: 'value', array: [1, 2]}
35
35
  },
36
36
  next_level_hash3: {
37
- deep_hash: { scalar: 'value', array: [1, 2] }
37
+ deep_hash: {scalar: 'value', array: [1, 2]}
38
38
  }
39
39
  }
40
40
  )
@@ -43,9 +43,9 @@ pointers = %w[
43
43
  x.report("Flat array whitelisting (action=#{action})") do
44
44
  preprocessor.process(
45
45
  nested_array: [
46
- { deep_array: [1, 2, 3] },
47
- { deep_array: [1, 2, 3] },
48
- { deep_array: [1, 2, 3] }
46
+ {deep_array: [1, 2, 3]},
47
+ {deep_array: [1, 2, 3]},
48
+ {deep_array: [1, 2, 3]}
49
49
  ]
50
50
  )
51
51
  end
@@ -1,25 +1,21 @@
1
- # coding: utf-8
2
- lib = File.expand_path('../lib', __FILE__)
1
+ # frozen_string_literal: true
2
+
3
+ lib = File.expand_path('lib', __dir__)
3
4
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
5
 
5
6
  Gem::Specification.new do |gem|
6
- if RUBY_PLATFORM =~ /java/
7
- gem.name = 'lenjador-jruby'
8
- else
9
- gem.name = 'lenjador'
10
- end
11
-
12
- gem.version = '1.2.1'
13
- gem.authors = ["Salemove"]
14
- gem.email = ["support@salemove.com"]
15
- gem.description = %q{It's lenjadoric}
16
- gem.summary = %q{What description said}
17
- gem.license = "MIT"
7
+ gem.name = RUBY_PLATFORM =~ /java/ ? 'lenjador-jruby' : 'lenjador'
8
+ gem.version = '1.3.0'
9
+ gem.authors = ['Salemove']
10
+ gem.email = ['support@salemove.com']
11
+ gem.description = "It's lenjadoric"
12
+ gem.summary = 'What description said'
13
+ gem.license = 'MIT'
18
14
 
19
- gem.files = `git ls-files`.split($/)
15
+ gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
20
16
  gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
17
  gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
22
- gem.require_paths = ["lib"]
18
+ gem.require_paths = ['lib']
23
19
 
24
20
  gem.add_dependency 'lru_redux'
25
21
 
@@ -27,10 +23,13 @@ Gem::Specification.new do |gem|
27
23
  gem.add_dependency 'jrjackson'
28
24
  else
29
25
  gem.add_dependency 'oj'
26
+ gem.add_development_dependency 'ruby-prof'
30
27
  end
31
28
 
32
- gem.add_development_dependency "bundler", "~> 1.3"
33
- gem.add_development_dependency "rake"
34
- gem.add_development_dependency "bunny"
35
- gem.add_development_dependency "benchmark-ips"
29
+ gem.add_development_dependency 'benchmark-ips'
30
+ gem.add_development_dependency 'bundler', '~> 1.3'
31
+ gem.add_development_dependency 'pry'
32
+ gem.add_development_dependency 'rake'
33
+ gem.add_development_dependency 'rspec'
34
+ gem.add_development_dependency 'rubocop-salemove'
36
35
  end
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'logger'
2
4
  require_relative 'lenjador/adapters'
3
5
  require_relative 'lenjador/utils'
4
6
  require_relative 'lenjador/null_logger'
5
7
  require_relative 'lenjador/preprocessors'
6
8
 
7
- LOG_LEVEL_QUERY_METHODS = [:debug?, :info?, :warn?, :error?, :fatal?]
9
+ LOG_LEVEL_QUERY_METHODS = %i[debug? info? warn? error? fatal?].freeze
8
10
 
9
11
  class Lenjador
10
12
  def self.build(service_name, loggers_config, preprocessors_config = {})
@@ -45,7 +47,7 @@ class Lenjador
45
47
 
46
48
  LOG_LEVEL_QUERY_METHODS.each do |method|
47
49
  define_method(method) do
48
- @adapters.any? {|adapter| adapter.public_send(method) }
50
+ @adapters.any? { |adapter| adapter.public_send(method) }
49
51
  end
50
52
  end
51
53
 
@@ -69,6 +71,6 @@ class Lenjador
69
71
  def parse_log_data(message = nil, metadata = {}, &block)
70
72
  return message if message.is_a?(Hash)
71
73
 
72
- (metadata || {}).merge(message: block ? block.call : message)
74
+ (metadata || {}).merge(message: block ? yield : message)
73
75
  end
74
76
  end
@@ -1,21 +1,21 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Lenjador
2
4
  module Adapters
3
- LOG_LEVELS = %w(debug info warn error fatal unknown).freeze
5
+ LOG_LEVELS = %i[debug info warn error fatal unknown].freeze
4
6
 
5
7
  def self.get(type, service_name, arguments)
8
+ raise "Unsupported logger: #{type}" if type != 'stdout'
9
+
6
10
  adapter =
7
- if type == 'stdout'
8
- if arguments.fetch(:json, false)
9
- require_relative 'adapters/stdout_json_adapter'
10
- StdoutJsonAdapter
11
- else
12
- require_relative 'adapters/stdout_adapter'
13
- StdoutAdapter
14
- end
11
+ if arguments.fetch(:json, false)
12
+ require_relative 'adapters/stdout_json_adapter'
13
+ StdoutJsonAdapter
15
14
  else
16
- raise "Unsupported logger: #{type}"
15
+ require_relative 'adapters/stdout_adapter'
16
+ StdoutAdapter
17
17
  end
18
- level = LOG_LEVELS.index(arguments.fetch(:level, 'debug'))
18
+ level = LOG_LEVELS.index(arguments.fetch(:level, :debug).to_sym)
19
19
  adapter.new(level, service_name, arguments)
20
20
  end
21
21
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'forwardable'
2
4
 
3
5
  class Lenjador
@@ -16,7 +18,7 @@ class Lenjador
16
18
 
17
19
  def log(level, metadata = {})
18
20
  message = metadata[:message]
19
- data = metadata.select { |key, value| key != :message }
21
+ data = metadata.reject { |key, _value| key == :message }
20
22
  log_data = [
21
23
  message,
22
24
  data.empty? ? nil : Utils.generate_json(data)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Lenjador
2
4
  module Adapters
3
5
  class StdoutJsonAdapter
@@ -5,14 +7,14 @@ class Lenjador
5
7
  @level = level
6
8
  @service_name = service_name
7
9
  @application_name = Utils.application_name(service_name)
8
- @mutex = Mutex.new if RUBY_ENGINE == "jruby"
10
+ @mutex = Mutex.new if RUBY_ENGINE == 'jruby'
9
11
  end
10
12
 
11
13
  def log(level, metadata = {})
12
- if meets_threshold?(level)
13
- message = Utils.build_event(metadata, level, @application_name)
14
- print_line(Utils.generate_json(message))
15
- end
14
+ return unless meets_threshold?(level)
15
+
16
+ message = Utils.build_event(metadata, level, @application_name)
17
+ print_line(Utils.generate_json(message))
16
18
  end
17
19
 
18
20
  def debug?
@@ -38,15 +40,15 @@ class Lenjador
38
40
  private
39
41
 
40
42
  def meets_threshold?(level)
41
- LOG_LEVELS.index(level.to_s) >= @level
43
+ LOG_LEVELS.index(level) >= @level
42
44
  end
43
45
 
44
46
  # puts is atomic in MRI starting from 2.5.0
45
- if RUBY_ENGINE == "ruby" && RUBY_VERSION >= "2.5.0"
47
+ if RUBY_ENGINE == 'ruby' && RUBY_VERSION >= '2.5.0'
46
48
  def print_line(str)
47
49
  $stdout.puts(str)
48
50
  end
49
- elsif RUBY_ENGINE == "jruby"
51
+ elsif RUBY_ENGINE == 'jruby'
50
52
  def print_line(str)
51
53
  @mutex.synchronize { $stdout.write(str + "\n") }
52
54
  end
@@ -1,18 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Lenjador
2
4
  class NullLogger
3
- def debug(*)
4
- end
5
+ def debug(*); end
5
6
 
6
- def info(*)
7
- end
7
+ def info(*); end
8
8
 
9
- def warn(*)
10
- end
9
+ def warn(*); end
11
10
 
12
- def error(*)
13
- end
11
+ def error(*); end
14
12
 
15
- def fatal(*)
16
- end
13
+ def fatal(*); end
17
14
  end
18
15
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Lenjador
2
4
  module Preprocessors
3
5
  def self.get(type, arguments)
@@ -1,12 +1,13 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Lenjador
2
4
  module Preprocessors
3
5
  class Blacklist
4
-
5
6
  DEFAULT_ACTION = 'prune'
6
7
  MASK_SYMBOL = '*'
7
8
  MASKED_VALUE = MASK_SYMBOL * 5
8
9
 
9
- class UnsupportedActionException < Exception
10
+ class UnsupportedActionException < RuntimeError
10
11
  end
11
12
 
12
13
  def initialize(config = {})
@@ -22,7 +23,7 @@ class Lenjador
22
23
  if data.is_a? Hash
23
24
  data.inject({}) do |mem, (key, val)|
24
25
  if (field = @fields_to_process[key.to_s])
25
- self.send(action_method(field[:action]), mem, key, val)
26
+ send(action_method(field[:action]), mem, key, val)
26
27
  else
27
28
  mem.merge(key => process(val))
28
29
  end
@@ -43,19 +44,19 @@ class Lenjador
43
44
  end
44
45
 
45
46
  def validate_action_supported(action)
46
- unless self.respond_to?(action_method(action).to_sym, true)
47
- raise UnsupportedActionException.new("Action: #{action} is not supported")
47
+ unless respond_to?(action_method(action).to_sym, true)
48
+ raise UnsupportedActionException, "Action: #{action} is not supported"
48
49
  end
49
50
  end
50
51
 
51
- def mask_field(data, key, val)
52
+ def mask_field(data, key, _val)
52
53
  data.merge(key => MASKED_VALUE)
53
54
  end
54
55
 
55
56
  def prune_field(data, *)
56
57
  data
57
58
  end
58
- alias_method :exclude_field, :prune_field
59
+ alias exclude_field prune_field
59
60
  end
60
61
  end
61
62
  end
@@ -1,10 +1,12 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'lru_redux'
2
4
 
3
5
  class Lenjador
4
6
  module Preprocessors
5
7
  class JSONPointerTrie
6
- SEPARATOR = '/'.freeze
7
- WILDCARD = '~'.freeze
8
+ SEPARATOR = '/'
9
+ WILDCARD = '~'
8
10
  DEFAULT_CACHE_SIZE = 100
9
11
 
10
12
  def initialize(cache_size: DEFAULT_CACHE_SIZE, **)
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Lenjador
2
4
  module Preprocessors
3
5
  module Strategies
4
6
  class Mask
5
- MASK_SYMBOL = '*'.freeze
7
+ MASK_SYMBOL = '*'
6
8
  MASKED_VALUE = MASK_SYMBOL * 5
7
9
 
8
10
  def initialize(trie)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  class Lenjador
2
4
  module Preprocessors
3
5
  module Strategies
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'lenjador/preprocessors/json_pointer_trie'
2
4
  require 'lenjador/preprocessors/strategies/mask'
3
5
  require 'lenjador/preprocessors/strategies/prune'
@@ -6,12 +8,12 @@ class Lenjador
6
8
  module Preprocessors
7
9
  class Whitelist
8
10
  DEFAULT_WHITELIST = %w[/id /message /correlation_id /queue].freeze
9
- MASK_SYMBOL = '*'.freeze
11
+ MASK_SYMBOL = '*'
10
12
  MASKED_VALUE = MASK_SYMBOL * 5
11
13
 
12
14
  PRUNE_ACTION_NAMES = %w[prune exclude].freeze
13
15
 
14
- class InvalidPointerFormatException < Exception
16
+ class InvalidPointerFormatException < RuntimeError
15
17
  end
16
18
 
17
19
  def initialize(config = {})
@@ -31,9 +33,7 @@ class Lenjador
31
33
  private
32
34
 
33
35
  def validate_pointer(pointer)
34
- if pointer.slice(-1) == '/'
35
- raise InvalidPointerFormatException, 'Pointer should not contain trailing slash'
36
- end
36
+ raise InvalidPointerFormatException, 'Pointer should not contain trailing slash' if pointer.slice(-1) == '/'
37
37
  end
38
38
 
39
39
  def decode(pointer)