contextual_logger 0.10.0 → 0.11.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: 2fe842aebc69d35423b8b06cb1c3dc270fc64d5541293c946dc8eb4f6bc274ed
4
- data.tar.gz: b3591004af708bd8722c313c222bf85dc4452053d2d2deb7c8abda72a500391e
3
+ metadata.gz: 0c5fcdf15e253eb8abb46dde530238633bd584f151e0282526dcfce923b4dc50
4
+ data.tar.gz: da4e10e4a778d244b2c36640ec4600bc76e4357fd4b0ddfbfef362c2276bbd5a
5
5
  SHA512:
6
- metadata.gz: f79aa7e16d8b788b8b641fd8d62109f67c4e566ee4bb90a816fd9cf894729bc74354bcb01935ff6f15a3ed330bb0ea56629d9ad7cc24ef4d3cbe68fe8203270c
7
- data.tar.gz: ec0406c0265718ee617a55f209e004805df6ce516d36a080680dda648e59ffd61ae48ebd654f1ced16db34c4bfcd83584002757b1abb8ce8fb6104582dca0307
6
+ metadata.gz: c575941e59fe7196d27528ea0733bd841eb47e45914f8b74add858227fc55161c2cbc2837653033f80ddfea3c3768538c137392d0e3a2b9f64c344982fb281ff
7
+ data.tar.gz: 199b5c2446a3fe1e6730b352dd23e93c0f9a52e04fffc335b28c6b26e0a2f5e3fe658b9949f57f87b3adba952e2b27ebc493e05dc5a3b2944baefcea0203e099
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require 'active_support/core_ext/hash/keys'
4
+
3
5
  module ContextualLogger
4
6
  # A logger that deep_merges additional context and then delegates to the given logger.
5
7
  # Keeps it own log level (called override_level) that may be set independently of the logger it delegates to.
@@ -13,7 +15,7 @@ module ContextualLogger
13
15
  logger.is_a?(LoggerMixin) or raise ArgumentError, "logger must include ContextualLogger::LoggerMixin (got #{logger.inspect})"
14
16
  @logger = logger
15
17
  self.level = level
16
- @context = context
18
+ @context = normalize_context(context)
17
19
  @merged_context_cache = {} # so we don't have to merge every time
18
20
  end
19
21
 
@@ -36,6 +38,29 @@ module ContextualLogger
36
38
  @logger.write_entry_to_log(severity, timestamp, progname, message, context: merged_context)
37
39
  end
38
40
 
41
+ private
42
+
43
+ def normalize_context(context)
44
+ if warn_on_string_keys(context)
45
+ context.deep_symbolize_keys
46
+ else
47
+ context
48
+ end
49
+ end
50
+
51
+ def warn_on_string_keys(context)
52
+ if deep_key_has_string?(context)
53
+ ActiveSupport::Deprecation.warn('Context keys must use symbols not strings. This will be asserted as of contextual_logger v1.0.0')
54
+ end
55
+ end
56
+
57
+ def deep_key_has_string?(hash)
58
+ hash.any? do |key, value|
59
+ key.is_a?(String) ||
60
+ (value.is_a?(Hash) && deep_key_has_string?(value))
61
+ end
62
+ end
63
+
39
64
  class << self
40
65
  def for_log_source(logger, log_source, level: nil)
41
66
  new(logger, { log_source: log_source }, level: level)
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ContextualLogger
4
- VERSION = '0.10.0'
4
+ VERSION = '0.11.0'
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: contextual_logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.11.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - James Ebentier
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-09-03 00:00:00.000000000 Z
11
+ date: 2020-09-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: json
@@ -56,7 +56,7 @@ licenses:
56
56
  metadata:
57
57
  source_code_uri: https://github.com/Invoca/contextual_logger
58
58
  allowed_push_host: https://rubygems.org
59
- post_install_message:
59
+ post_install_message:
60
60
  rdoc_options: []
61
61
  require_paths:
62
62
  - lib
@@ -72,7 +72,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
72
72
  version: '0'
73
73
  requirements: []
74
74
  rubygems_version: 3.0.3
75
- signing_key:
75
+ signing_key:
76
76
  specification_version: 4
77
77
  summary: Add context to your logger
78
78
  test_files: []