sapience 2.14 → 2.15

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
- SHA1:
3
- metadata.gz: 5ef38812e94717d5c17cbc973d7aef79deb1905a
4
- data.tar.gz: c95f1ae7e46b15e7e9bbbac99ed2bad8705cfc9b
2
+ SHA256:
3
+ metadata.gz: a617af7787dbacebb45f2dcbfd6ec0c930e1d436488d37507bbd85e2f2856778
4
+ data.tar.gz: 68ebecc04c1377f17fd48d9f3e24cd0eab3b8bc813e14aa237426472e7377fc5
5
5
  SHA512:
6
- metadata.gz: 7d4106483c8d8f01f3b8e869b4930f0a7a702702060d84052513a0b3ea8d481ce7df9d4eb4a352c9b9389e5306234726e2ad4ddbac5593cd19f385f9c696c993
7
- data.tar.gz: ff0ad620ddb060381b8ce51f0579b9dcb8230920fe3bd27b594a83507584f0a74938119f1b344dbbfcd0eeb452f6399ac8ec1c8f0d54ea92be7a9004627ef107
6
+ metadata.gz: 64ac6ba2a9084b6903aec351acc2811b272502a00ea366e80bc060e687fd2b6ad86aec8d348bdcc5f7ed1655369ef1d59c0441255ff46c37d7c5ebefeaa58df9
7
+ data.tar.gz: f514453bb97eb2a139b0c5139fc8a2e6215299f47a60da60df849e982fbc98da51f85e74dfa8b927bdf7fde753f0af20a9de5a3358120804cd66751e03f64433
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- 2.4.10
1
+ 2.4.9
data/CHANGELOG.md CHANGED
@@ -1,3 +1,7 @@
1
+ ## v2.15
2
+ - The Formatter can now be configured to exclude selected log fields.
3
+ Currently only the Json formatter implements this.
4
+
1
5
  ## v2.13
2
6
  - Add config option to enable/disable metrics from grape
3
7
 
@@ -13,6 +13,58 @@ Formatters can be specified by using the key `formatter: :camelized_formatter_na
13
13
  ### JSON
14
14
 
15
15
  `formatter: :json` - logs are saved as a single line json. Useful for production like environments.
16
+ The json formatter can be configured to filter out select log fields. The following configuration demonstrates this:
17
+
18
+ ```yaml
19
+ json_formatter: &json_slim
20
+ json:
21
+ exclude_fields:
22
+ - "name"
23
+ - "request_id"
24
+ - "thread"
25
+ - "pid"
26
+ - "level_index"
27
+ - "host"
28
+ - "app_name"
29
+ - "request_id"
30
+ - "action"
31
+ - "controller"
32
+ - "route"
33
+ - "file"
34
+ - "line"
35
+ - "format"
36
+ - "tags"
37
+
38
+ ci:
39
+ log_level: warn
40
+ appenders:
41
+ - stream:
42
+ io: STDOUT
43
+ formatter: color
44
+
45
+ production:
46
+ log_level: info
47
+ appenders:
48
+ - stream:
49
+ io: STDOUT
50
+ formatter:
51
+ <<: *json_slim
52
+
53
+ staging:
54
+ log_level: info
55
+ appenders:
56
+ - stream:
57
+ io: STDOUT
58
+ formatter:
59
+ <<: *json_slim
60
+
61
+ development:
62
+ log_level: debug
63
+ appenders:
64
+ - stream:
65
+ io: STDOUT
66
+ formatter: json
67
+ ```
16
68
 
17
69
  ### RAW
18
70
 
@@ -70,12 +70,13 @@ module Sapience
70
70
  if YAML.respond_to?(:safe_load) # Ruby 2.1+
71
71
  if defined?(SafeYAML) && SafeYAML.respond_to?(:load)
72
72
  SafeYAML.load(yaml_code, filename,
73
- whitelisted_tags: %w(!ruby/regexp))
73
+ whitelisted_tags: %w(!ruby/regexp),
74
+ aliases: true)
74
75
  else
75
- YAML.safe_load(yaml_code, [Regexp], [], false, filename)
76
+ YAML.safe_load(yaml_code, [Regexp], [], true, filename)
76
77
  end
77
78
  else
78
- YAML.safe_load(yaml_code, filename)
79
+ YAML.safe_load(yaml_code, filename, aliases: true)
79
80
  end
80
81
  end
81
82
  end
@@ -2,7 +2,7 @@
2
2
  module Sapience
3
3
  module Formatters
4
4
  class Base
5
- attr_accessor :time_format, :precision, :log_host, :log_application
5
+ attr_accessor :time_format, :default_time_format, :precision, :log_host, :log_application, :exclude_fields
6
6
 
7
7
  # Parameters
8
8
  # time_format: [String|Symbol|nil]
@@ -11,13 +11,9 @@ module Sapience
11
11
  # nil: Returns Empty string for time ( no time is output ).
12
12
  # Default: '%Y-%m-%d %H:%M:%S.%6N'
13
13
  def initialize(options = {})
14
- options = options.dup
15
- @precision = 6
16
- default_format = "%Y-%m-%d %H:%M:%S.%#{precision}N"
17
- @time_format = options.key?(:time_format) ? options.delete(:time_format) : default_format
18
- @log_host = options.key?(:log_host) ? options.delete(:log_host) : true
19
- @log_application = options.key?(:log_application) ? options.delete(:log_application) : true
20
- fail(ArgumentError, "Unknown options: #{options.inspect}") unless options.empty?
14
+ @precision = 6
15
+ @default_time_format = "%Y-%m-%d %H:%M:%S.%#{precision}N"
16
+ parse_options(options.dup)
21
17
  end
22
18
 
23
19
  # Return the Time as a formatted string
@@ -32,6 +28,15 @@ module Sapience
32
28
  end
33
29
  end
34
30
 
31
+ private
32
+
33
+ def parse_options(options)
34
+ @time_format = options.key?(:time_format) ? options.delete(:time_format) : default_time_format
35
+ @log_host = options.key?(:log_host) ? options.delete(:log_host) : true
36
+ @log_application = options.key?(:log_application) ? options.delete(:log_application) : true
37
+ @exclude_fields = options.key?(:exclude_fields) ? options.delete(:exclude_fields).map(&:to_sym) : {}
38
+ fail(ArgumentError, "Unknown options: #{options.inspect}") unless options.empty?
39
+ end
35
40
  end
36
41
  end
37
42
  end
@@ -13,9 +13,25 @@ module Sapience
13
13
  # Returns log messages in JSON format
14
14
  def call(log, logger)
15
15
  h = super(log, logger)
16
- h.delete(:time)
17
- h[:timestamp] = format_time(log.time)
18
- h.to_json
16
+ prepare(h, log).to_json
17
+ end
18
+
19
+ private
20
+
21
+ def prepare(log_hash, log)
22
+ set_timestamp(log_hash, log)
23
+ remove_fields(log_hash)
24
+ log_hash
25
+ end
26
+
27
+ def set_timestamp(log_hash, log)
28
+ log_hash.delete(:time)
29
+ log_hash[:timestamp] = format_time(log.time)
30
+ log_hash
31
+ end
32
+
33
+ def remove_fields(log_hash)
34
+ log_hash.delete_if { |k, _v| exclude_fields.include?(k.to_sym) } if exclude_fields.any?
19
35
  end
20
36
  end
21
37
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Sapience
3
- VERSION = "2.14"
3
+ VERSION = "2.15"
4
4
  end
data/sapience.gemspec CHANGED
@@ -28,7 +28,7 @@ Gem::Specification.new do |spec|
28
28
  spec.add_dependency "concurrent-ruby", "~> 1.0"
29
29
  spec.add_development_dependency "active_model_serializers", "~> 0.10.0"
30
30
  spec.add_development_dependency "appraisal"
31
- spec.add_development_dependency "bundler"
31
+ spec.add_development_dependency "bundler", "~> 1"
32
32
  spec.add_development_dependency "codeclimate-test-reporter"
33
33
  spec.add_development_dependency "dogstatsd-ruby", "~> 2.0"
34
34
  spec.add_development_dependency "fuubar"
@@ -36,7 +36,7 @@ Gem::Specification.new do |spec|
36
36
  spec.add_development_dependency "grape"
37
37
  spec.add_development_dependency "memory_profiler"
38
38
  spec.add_development_dependency "pry-nav"
39
- spec.add_development_dependency "rails", "~> 5.0"
39
+ spec.add_development_dependency "rails", "~> 5.0.0.1"
40
40
  spec.add_development_dependency "rake"
41
41
  spec.add_development_dependency "reevoocop"
42
42
  spec.add_development_dependency "rspec", "~> 3.0"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sapience
3
3
  version: !ruby/object:Gem::Version
4
- version: '2.14'
4
+ version: '2.15'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mikael Henriksson
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2021-03-29 00:00:00.000000000 Z
12
+ date: 2021-05-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: concurrent-ruby
@@ -57,16 +57,16 @@ dependencies:
57
57
  name: bundler
58
58
  requirement: !ruby/object:Gem::Requirement
59
59
  requirements:
60
- - - ">="
60
+ - - "~>"
61
61
  - !ruby/object:Gem::Version
62
- version: '0'
62
+ version: '1'
63
63
  type: :development
64
64
  prerelease: false
65
65
  version_requirements: !ruby/object:Gem::Requirement
66
66
  requirements:
67
- - - ">="
67
+ - - "~>"
68
68
  - !ruby/object:Gem::Version
69
- version: '0'
69
+ version: '1'
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: codeclimate-test-reporter
72
72
  requirement: !ruby/object:Gem::Requirement
@@ -171,14 +171,14 @@ dependencies:
171
171
  requirements:
172
172
  - - "~>"
173
173
  - !ruby/object:Gem::Version
174
- version: '5.0'
174
+ version: 5.0.0.1
175
175
  type: :development
176
176
  prerelease: false
177
177
  version_requirements: !ruby/object:Gem::Requirement
178
178
  requirements:
179
179
  - - "~>"
180
180
  - !ruby/object:Gem::Version
181
- version: '5.0'
181
+ version: 5.0.0.1
182
182
  - !ruby/object:Gem::Dependency
183
183
  name: rake
184
184
  requirement: !ruby/object:Gem::Requirement
@@ -404,8 +404,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
404
404
  - !ruby/object:Gem::Version
405
405
  version: '0'
406
406
  requirements: []
407
- rubyforge_project:
408
- rubygems_version: 2.6.14.4
407
+ rubygems_version: 3.0.3
409
408
  signing_key:
410
409
  specification_version: 4
411
410
  summary: Hasslefree autoconfiguration for logging, metrics and exception collection.