lenjador 1.2.1 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.rubocop.yml +41 -0
- data/.ruby-version +1 -1
- data/.travis.yml +1 -3
- data/Gemfile +1 -6
- data/Rakefile +6 -4
- data/benchmark/whitelisting.rb +7 -7
- data/lenjador.gemspec +21 -26
- data/lib/lenjador.rb +38 -23
- data/lib/lenjador/adapters.rb +9 -14
- data/lib/lenjador/adapters/stdout_adapter.rb +6 -9
- data/lib/lenjador/adapters/stdout_json_adapter.rb +10 -36
- data/lib/lenjador/null_logger.rb +7 -10
- data/lib/lenjador/preprocessors.rb +2 -0
- data/lib/lenjador/preprocessors/blacklist.rb +11 -9
- data/lib/lenjador/preprocessors/json_pointer_trie.rb +4 -2
- data/lib/lenjador/preprocessors/strategies/mask.rb +3 -1
- data/lib/lenjador/preprocessors/strategies/prune.rb +2 -0
- data/lib/lenjador/preprocessors/whitelist.rb +6 -6
- data/lib/lenjador/utils.rb +42 -43
- data/profiler/logs.rb +19 -0
- data/spec/lenjador/adapters/stdout_adapter_spec.rb +48 -0
- data/spec/lenjador/adapters/stdout_json_adapter_spec.rb +46 -0
- data/spec/{preprocessors → lenjador/preprocessors}/blacklist_spec.rb +18 -14
- data/spec/{preprocessors/json_pointer_trie.rb → lenjador/preprocessors/json_pointer_trie_spec.rb} +4 -4
- data/spec/lenjador/preprocessors/whitelist_spec.rb +319 -0
- data/spec/lenjador/utils_spec.rb +99 -0
- data/spec/lenjador_spec.rb +41 -33
- data/spec/spec_helper.rb +1 -1
- metadata +67 -24
- data/spec/adapters/stdout_adapter_spec.rb +0 -48
- data/spec/adapters/stdout_json_adapter_spec.rb +0 -62
- data/spec/preprocessors/whitelist_spec.rb +0 -335
- data/spec/utils_spec.rb +0 -84
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 5d96edbeff69ee13444e45a5924d8fedd4907725831f9ce62fd2f3280b48b244
|
4
|
+
data.tar.gz: b7e501d6a7dba6b7461df12e72530796900a4241700dd676c48d6e6f8341e0b2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b1142e4a26fb13f3ba2d880de8c3b58e18eacc77de055d36b10c3a9783c6c1d597a50aab94f1611a43fc17f8490f6598049da6f5d4c9ed73af77be2fa5ccb26e
|
7
|
+
data.tar.gz: 6f6d29354c80eae57485fc2f3fa5f6e0643aad692763957ab43c8ba3041a8f5d9cbba6fb3e9453a121c6634d5e7e776d82df0286a966b97613d03c437b602827
|
data/.rubocop.yml
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
inherit_gem:
|
2
|
+
rubocop-salemove: config/default.yml
|
3
|
+
|
4
|
+
AllCops:
|
5
|
+
TargetRubyVersion: 2.4
|
6
|
+
|
7
|
+
Style/FrozenStringLiteralComment:
|
8
|
+
Enabled: yes
|
9
|
+
EnforcedStyle: always
|
10
|
+
Include:
|
11
|
+
- 'lib/**/*'
|
12
|
+
|
13
|
+
Metrics/MethodLength:
|
14
|
+
Enabled: no
|
15
|
+
|
16
|
+
Style/GuardClause:
|
17
|
+
Enabled: no
|
18
|
+
|
19
|
+
RSpec/VerifiedDoubles:
|
20
|
+
Enabled: no
|
21
|
+
|
22
|
+
Metrics/BlockLength:
|
23
|
+
Enabled: no
|
24
|
+
|
25
|
+
RSpec/MessageSpies:
|
26
|
+
Enabled: no
|
27
|
+
|
28
|
+
RSpec/ExpectOutput:
|
29
|
+
Enabled: no
|
30
|
+
|
31
|
+
RSpec/ExampleLength:
|
32
|
+
Enabled: no
|
33
|
+
|
34
|
+
RSpec/MultipleExpectations:
|
35
|
+
Enabled: no
|
36
|
+
|
37
|
+
Style/SafeNavigation:
|
38
|
+
Enabled: no
|
39
|
+
|
40
|
+
Style/SingleLineMethods:
|
41
|
+
Enabled: no
|
data/.ruby-version
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby-2.
|
1
|
+
ruby-2.7.1
|
data/.travis.yml
CHANGED
data/Gemfile
CHANGED
data/Rakefile
CHANGED
@@ -1,7 +1,9 @@
|
|
1
|
-
require
|
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
|
-
|
7
|
-
|
7
|
+
RuboCop::RakeTask.new(:rubocop)
|
8
|
+
|
9
|
+
task default: %i[rubocop spec]
|
data/benchmark/whitelisting.rb
CHANGED
@@ -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: {
|
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: {
|
31
|
+
deep_hash: {scalar: 'value', array: [1, 2]}
|
32
32
|
},
|
33
33
|
next_level_hash2: {
|
34
|
-
deep_hash: {
|
34
|
+
deep_hash: {scalar: 'value', array: [1, 2]}
|
35
35
|
},
|
36
36
|
next_level_hash3: {
|
37
|
-
deep_hash: {
|
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
|
-
{
|
47
|
-
{
|
48
|
-
{
|
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
|
data/lenjador.gemspec
CHANGED
@@ -1,36 +1,31 @@
|
|
1
|
-
#
|
2
|
-
|
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
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
gem.
|
13
|
-
gem.
|
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 = 'lenjador'
|
8
|
+
gem.version = '2.1.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'
|
14
|
+
gem.required_ruby_version = '>= 2.4'
|
18
15
|
|
19
|
-
gem.files = `git ls-files`.split(
|
16
|
+
gem.files = `git ls-files`.split($INPUT_RECORD_SEPARATOR)
|
20
17
|
gem.executables = gem.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
21
18
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
22
|
-
gem.require_paths = [
|
19
|
+
gem.require_paths = ['lib']
|
23
20
|
|
24
21
|
gem.add_dependency 'lru_redux'
|
22
|
+
gem.add_dependency 'oj', '~> 3.6'
|
25
23
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
gem.add_development_dependency
|
33
|
-
gem.add_development_dependency "rake"
|
34
|
-
gem.add_development_dependency "bunny"
|
35
|
-
gem.add_development_dependency "benchmark-ips"
|
24
|
+
gem.add_development_dependency 'benchmark-ips'
|
25
|
+
gem.add_development_dependency 'bundler'
|
26
|
+
gem.add_development_dependency 'pry'
|
27
|
+
gem.add_development_dependency 'rake'
|
28
|
+
gem.add_development_dependency 'rspec'
|
29
|
+
gem.add_development_dependency 'rubocop-salemove'
|
30
|
+
gem.add_development_dependency 'ruby-prof'
|
36
31
|
end
|
data/lib/lenjador.rb
CHANGED
@@ -1,63 +1,78 @@
|
|
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?]
|
8
|
-
|
9
9
|
class Lenjador
|
10
|
-
|
11
|
-
|
10
|
+
Severity = ::Logger::Severity
|
11
|
+
SEV_LABEL = %w[debug info warn error fatal any].freeze
|
12
|
+
|
13
|
+
def self.build(service_name, logger_config, preprocessors_config = {})
|
14
|
+
logger_config ||= {}
|
15
|
+
|
12
16
|
preprocessors = preprocessors_config.map do |type, arguments|
|
13
17
|
Preprocessors.get(type.to_s, arguments || {})
|
14
18
|
end
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
new(
|
19
|
+
adapter = Adapters.get(service_name, logger_config)
|
20
|
+
level = SEV_LABEL.index(logger_config.fetch(:level, 'debug'))
|
21
|
+
|
22
|
+
new(adapter, level, preprocessors)
|
19
23
|
end
|
20
24
|
|
21
|
-
def initialize(
|
22
|
-
@
|
25
|
+
def initialize(adapter, level, preprocessors)
|
26
|
+
@adapter = adapter
|
27
|
+
@level = level
|
23
28
|
@preprocessors = preprocessors
|
24
29
|
end
|
25
30
|
|
26
31
|
def debug(*args, &block)
|
27
|
-
log
|
32
|
+
log(Severity::DEBUG, *args, &block)
|
28
33
|
end
|
29
34
|
|
30
35
|
def info(*args, &block)
|
31
|
-
log
|
36
|
+
log(Severity::INFO, *args, &block)
|
32
37
|
end
|
33
38
|
|
34
39
|
def warn(*args, &block)
|
35
|
-
log
|
40
|
+
log(Severity::WARN, *args, &block)
|
36
41
|
end
|
37
42
|
|
38
43
|
def error(*args, &block)
|
39
|
-
log
|
44
|
+
log(Severity::ERROR, *args, &block)
|
40
45
|
end
|
41
46
|
|
42
47
|
def fatal(*args, &block)
|
43
|
-
log
|
48
|
+
log(Severity::FATAL, *args, &block)
|
44
49
|
end
|
45
50
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
51
|
+
def debug?; @level <= Severity::DEBUG; end
|
52
|
+
|
53
|
+
def info?; @level <= Severity::INFO; end
|
54
|
+
|
55
|
+
def warn?; @level <= Severity::WARN; end
|
56
|
+
|
57
|
+
def error?; @level <= Severity::ERROR; end
|
58
|
+
|
59
|
+
def fatal?; @level <= Severity::FATAL; end
|
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
|
50
65
|
end
|
51
66
|
|
52
67
|
private
|
53
68
|
|
54
69
|
def log(level, *args, &block)
|
70
|
+
return true if level < @level
|
71
|
+
|
55
72
|
data = parse_log_data(*args, &block)
|
56
73
|
processed_data = preprocess(data)
|
57
74
|
|
58
|
-
@
|
59
|
-
adapter.log(level, processed_data)
|
60
|
-
end
|
75
|
+
@adapter.log(level, processed_data)
|
61
76
|
end
|
62
77
|
|
63
78
|
def preprocess(data)
|
@@ -69,6 +84,6 @@ class Lenjador
|
|
69
84
|
def parse_log_data(message = nil, metadata = {}, &block)
|
70
85
|
return message if message.is_a?(Hash)
|
71
86
|
|
72
|
-
(metadata || {}).merge(message: block ?
|
87
|
+
(metadata || {}).merge(message: block ? yield : message)
|
73
88
|
end
|
74
89
|
end
|
data/lib/lenjador/adapters.rb
CHANGED
@@ -1,22 +1,17 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Lenjador
|
2
4
|
module Adapters
|
3
|
-
|
4
|
-
|
5
|
-
def self.get(type, service_name, arguments)
|
5
|
+
def self.get(service_name, config)
|
6
6
|
adapter =
|
7
|
-
if
|
8
|
-
|
9
|
-
|
10
|
-
StdoutJsonAdapter
|
11
|
-
else
|
12
|
-
require_relative 'adapters/stdout_adapter'
|
13
|
-
StdoutAdapter
|
14
|
-
end
|
7
|
+
if config.fetch(:json, false)
|
8
|
+
require_relative 'adapters/stdout_json_adapter'
|
9
|
+
StdoutJsonAdapter
|
15
10
|
else
|
16
|
-
|
11
|
+
require_relative 'adapters/stdout_adapter'
|
12
|
+
StdoutAdapter
|
17
13
|
end
|
18
|
-
|
19
|
-
adapter.new(level, service_name, arguments)
|
14
|
+
adapter.new(service_name)
|
20
15
|
end
|
21
16
|
end
|
22
17
|
end
|
@@ -1,28 +1,25 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
require 'forwardable'
|
2
4
|
|
3
5
|
class Lenjador
|
4
6
|
module Adapters
|
5
7
|
class StdoutAdapter
|
6
|
-
extend Forwardable
|
7
|
-
|
8
8
|
attr_reader :logger
|
9
9
|
|
10
|
-
|
11
|
-
|
12
|
-
def initialize(level, *)
|
13
|
-
@logger = Logger.new(STDOUT)
|
14
|
-
@logger.level = level
|
10
|
+
def initialize(_service_name)
|
11
|
+
@logger = Logger.new($stdout)
|
15
12
|
end
|
16
13
|
|
17
14
|
def log(level, metadata = {})
|
18
15
|
message = metadata[:message]
|
19
|
-
data = metadata.
|
16
|
+
data = metadata.reject { |key, _value| key == :message }
|
20
17
|
log_data = [
|
21
18
|
message,
|
22
19
|
data.empty? ? nil : Utils.generate_json(data)
|
23
20
|
].compact.join(' ')
|
24
21
|
|
25
|
-
@logger.
|
22
|
+
@logger.add(level, log_data)
|
26
23
|
end
|
27
24
|
end
|
28
25
|
end
|
@@ -1,58 +1,32 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
class Lenjador
|
2
4
|
module Adapters
|
3
5
|
class StdoutJsonAdapter
|
4
|
-
def initialize(
|
5
|
-
@level = level
|
6
|
-
@service_name = service_name
|
6
|
+
def initialize(service_name)
|
7
7
|
@application_name = Utils.application_name(service_name)
|
8
|
-
@mutex = Mutex.new if RUBY_ENGINE ==
|
8
|
+
@mutex = Mutex.new if RUBY_ENGINE == 'jruby'
|
9
9
|
end
|
10
10
|
|
11
11
|
def log(level, metadata = {})
|
12
|
-
|
13
|
-
|
14
|
-
print_line(Utils.generate_json(message))
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
|
-
def debug?
|
19
|
-
meets_threshold?(:debug)
|
20
|
-
end
|
21
|
-
|
22
|
-
def info?
|
23
|
-
meets_threshold?(:info)
|
24
|
-
end
|
25
|
-
|
26
|
-
def warn?
|
27
|
-
meets_threshold?(:warn)
|
28
|
-
end
|
29
|
-
|
30
|
-
def error?
|
31
|
-
meets_threshold?(:error)
|
32
|
-
end
|
33
|
-
|
34
|
-
def fatal?
|
35
|
-
meets_threshold?(:fatal)
|
12
|
+
message = Utils.build_event(metadata, Lenjador::SEV_LABEL[level], @application_name)
|
13
|
+
print_line(Utils.generate_json(message))
|
36
14
|
end
|
37
15
|
|
38
16
|
private
|
39
17
|
|
40
|
-
def meets_threshold?(level)
|
41
|
-
LOG_LEVELS.index(level.to_s) >= @level
|
42
|
-
end
|
43
|
-
|
44
18
|
# puts is atomic in MRI starting from 2.5.0
|
45
|
-
if RUBY_ENGINE ==
|
19
|
+
if RUBY_ENGINE == 'ruby' && RUBY_VERSION >= '2.5.0'
|
46
20
|
def print_line(str)
|
47
21
|
$stdout.puts(str)
|
48
22
|
end
|
49
|
-
elsif RUBY_ENGINE ==
|
23
|
+
elsif RUBY_ENGINE == 'jruby'
|
50
24
|
def print_line(str)
|
51
|
-
@mutex.synchronize { $stdout.write(str
|
25
|
+
@mutex.synchronize { $stdout.write("#{str}\n") }
|
52
26
|
end
|
53
27
|
else
|
54
28
|
def print_line(str)
|
55
|
-
$stdout.write(str
|
29
|
+
$stdout.write("#{str}\n")
|
56
30
|
end
|
57
31
|
end
|
58
32
|
end
|
data/lib/lenjador/null_logger.rb
CHANGED
@@ -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
|