dry-logger 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8ade638e79062ec058eb9745a134da64d4a97a6ee0ae794ebddc60c2463e7a74
4
- data.tar.gz: f68f26b0565381b9a1d1c347d7be52d4d38a6cea69cfa2d60daaacc7a57b5124
3
+ metadata.gz: 64477022ad878f3e1a98d7fb8b82bb9117b8d09c662ecf12b89fda0bca0bc8dd
4
+ data.tar.gz: f69f6a4d5a1daf532f4a569789fa9e087b44889cdb6f47b048e5d3961a93a893
5
5
  SHA512:
6
- metadata.gz: 4f12c24a3bee1e597b5eabdfe2b0905e2c94bd22821ec979092ad369bfa0d120f4ff84f8fd20cad9a15b6620e33036cc34e682790fb27f78952136c0cd09e0a5
7
- data.tar.gz: cbca9d7176c727f69b82a99ce0fca122c8084c702a16525cbe9c24ff6c7155d845debfcde5b455a969930b7cb24baecad1bab3790f8843f7e7469d83eb85fb57
6
+ metadata.gz: 4ed4f26c990c6e85575fd06f5064fbd68ca73a11ecb4370e749455cc980edf319905e672d7f2bc798ec0f80df235f0c86cf1b50786eb891b71fb142b2a2c4590
7
+ data.tar.gz: 527a960b08d0083fbbbc086e5b946d896021ff0d3295916c42eed5f41e5d1131d15633e7d0926cb7dbe528098c0943e965189a5e0c6076845bc567bd04c6d96a
data/CHANGELOG.md CHANGED
@@ -1,63 +1,75 @@
1
- <!--- DO NOT EDIT THIS FILE - IT'S AUTOMATICALLY GENERATED VIA DEVTOOLS --->
1
+ # Changelog
2
2
 
3
- ## 1.1.0 2025-04-17
3
+ All notable changes to this project will be documented in this file.
4
4
 
5
- ### Added
5
+ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
+ and this project adheres to [Break Versioning](https://www.taoensso.com/break-versioning).
6
7
 
7
- - Support `::Logger`'s log rotation in stream-based logger backends, via `shift_size:` and `shift_age:` arguments (@wuarmin in #31)
8
+ ## [Unreleased]
8
9
 
9
- [Compare v1.0.4...v1.1.0](https://github.com/dry-rb/dry-logger/compare/v1.0.4...v1.1.0)
10
+ ### Added
10
11
 
11
- ## 1.0.4 2024-05-10
12
+ ### Changed
12
13
 
14
+ ### Deprecated
15
+
16
+ ### Removed
13
17
 
14
18
  ### Fixed
15
19
 
16
- - Accept log messages via given block, ensuring compatibility with standard Ruby logger (via #28) (@komidore64)
20
+ ### Security
21
+
22
+ ## [1.2.0] - 2025-11-05
17
23
 
18
24
  ### Changed
19
25
 
20
- - Drop support for Ruby 2.7 (via #29) (@timriley)
26
+ - When a block is given when logging, do not execute the block if the severity is lower than the configured logger level. (@p8 in #33)
27
+ - When a block is given when logging, and that block returns a hash, use that hash as the log payload. (@p8 in #34)
21
28
 
22
- [Compare v1.0.3...v1.0.4](https://github.com/dry-rb/dry-logger/compare/v1.0.3...v1.0.4)
29
+ ### Fixed
23
30
 
24
- ## 1.0.3 2022-12-09
31
+ - When filtering logged data, filter on a copy of the given hash, rather then mutating it directly. (@timriley in #35)
25
32
 
33
+ ## [1.1.0] - 2025-04-17
26
34
 
27
35
  ### Added
28
36
 
29
- - Support for ruby 2.7 (needs backports gem that *you* need to add to your Gemfile) (via #24) (@solnic)
37
+ - Support `::Logger`'s log rotation in stream-based logger backends, via `shift_size:` and `shift_age:` arguments (@wuarmin in #31)
30
38
 
39
+ ## [1.0.4] - 2024-05-10
31
40
 
32
- [Compare v1.0.2...v1.0.3](https://github.com/dry-rb/dry-logger/compare/v1.0.2...v1.0.3)
41
+ ### Fixed
33
42
 
34
- ## 1.0.2 2022-11-24
43
+ - Accept log messages via given block, ensuring compatibility with standard Ruby logger (via #28) (@komidore64)
35
44
 
45
+ ### Changed
36
46
 
37
- ### Fixed
47
+ - Drop support for Ruby 2.7 (via #29) (@timriley)
38
48
 
39
- - Handle `:log_if` in Proxy constructors (via #23) (@solnic)
49
+ ## [1.0.3] - 2022-12-09
40
50
 
51
+ ### Added
41
52
 
42
- [Compare v1.0.1...v1.0.2](https://github.com/dry-rb/dry-logger/compare/v1.0.1...v1.0.2)
53
+ - Support for ruby 2.7 (needs backports gem that *you* need to add to your Gemfile) (via #24) (@solnic)
43
54
 
44
- ## 1.0.1 2022-11-23
55
+ ## [1.0.2] - 2022-11-24
45
56
 
57
+ ### Fixed
58
+
59
+ - Handle `:log_if` in Proxy constructors (via #23) (@solnic)
60
+
61
+ ## [1.0.1] - 2022-11-23
46
62
 
47
63
  ### Fixed
48
64
 
49
65
  - Support for `log_if` in proxied loggers (via 81115320b490034ddf9dfe4f3775322b9271e0cd) (@solnic)
50
66
  - Support exceptions and payloads in proxied loggers (via 93b3fd59ebbdc7e63620eb064694d58455df831f) (@solnic)
51
67
 
52
-
53
- [Compare v1.0.0...v1.0.1](https://github.com/dry-rb/dry-logger/compare/v1.0.0...v1.0.1)
54
-
55
- ## 1.0.0 2022-11-17
68
+ ## [1.0.0] - 2022-11-17
56
69
 
57
70
  This is a port of the original Hanami logger from hanami-utils extended with support for logging
58
71
  dispatchers that can log to different destinations and plenty more.
59
72
 
60
-
61
73
  ### Added
62
74
 
63
75
  - Support arbitrary logging backends through proxy (via #12) (@solnic)
@@ -78,3 +90,11 @@ dispatchers that can log to different destinations and plenty more.
78
90
  - `:rack` string log formatter which inlines request info and displays params at the end (@solnic)
79
91
  - Conditional log dispatch via `#log_if` backend's predicate (via #9) (@solnic)
80
92
  - Add support for shared context and tagged log entries (via #10) (@solnic)
93
+
94
+ [1.2.0]: https://github.com/dry-rb/dry-logger/compare/v1.1.0...v1.2.0
95
+ [1.1.0]: https://github.com/dry-rb/dry-logger/compare/v1.0.4...v1.1.0
96
+ [1.0.4]: https://github.com/dry-rb/dry-logger/compare/v1.0.3...v1.0.4
97
+ [1.0.3]: https://github.com/dry-rb/dry-logger/compare/v1.0.2...v1.0.3
98
+ [1.0.2]: https://github.com/dry-rb/dry-logger/compare/v1.0.1...v1.0.2
99
+ [1.0.1]: https://github.com/dry-rb/dry-logger/compare/v1.0.0...v1.0.1
100
+ [1.0.0]: https://github.com/dry-rb/dry-logger/releases/tag/v1.0.0
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2015-2023 dry-rb team
3
+ Copyright (c) 2015-2025 Hanakai team
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy of
6
6
  this software and associated documentation files (the "Software"), to deal in
@@ -18,3 +18,4 @@ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
18
  COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
19
  IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
20
  CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21
+
data/README.md CHANGED
@@ -1,23 +1,17 @@
1
- <!--- this file is synced from dry-rb/template-gem project -->
1
+ <!--- This file is synced from hanakai-rb/repo-sync -->
2
2
 
3
- [gem]: https://rubygems.org/gems/dry-logger
3
+ [rubygem]: https://rubygems.org/gems/dry-logger
4
4
  [actions]: https://github.com/dry-rb/dry-logger/actions
5
5
 
6
- # dry-logger [![Gem Version](https://badge.fury.io/rb/dry-logger.svg)][gem] [![CI Status](https://github.com/dry-rb/dry-logger/workflows/CI/badge.svg)][actions]
6
+ # dry-logger [![Gem Version](https://badge.fury.io/rb/dry-logger.svg)][rubygem] [![CI Status](https://github.com/dry-rb/dry-logger/workflows/CI/badge.svg)][actions]
7
7
 
8
8
  ## Links
9
9
 
10
- * [User documentation](https://dry-rb.org/gems/dry-logger)
11
- * [API documentation](http://rubydoc.info/gems/dry-logger)
12
- * [Forum](https://discourse.dry-rb.org)
13
-
14
- ## Supported Ruby versions
15
-
16
- This library officially supports the following Ruby versions:
17
-
18
- * MRI `>= 3.0`
19
- * jruby `>= 9.4` (not tested on CI)
10
+ - [User documentation](https://dry-rb.org/gems/dry-logger)
11
+ - [API documentation](http://rubydoc.info/gems/dry-logger)
12
+ - [Forum](https://discourse.dry-rb.org)
20
13
 
21
14
  ## License
22
15
 
23
16
  See `LICENSE` file.
17
+
data/dry-logger.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- # this file is synced from dry-rb/template-gem project
3
+ # This file is synced from hanakai-rb/repo-sync. To update it, edit repo-sync.yml.
4
4
 
5
5
  lib = File.expand_path("lib", __dir__)
6
6
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
@@ -8,12 +8,12 @@ require "dry/logger/version"
8
8
 
9
9
  Gem::Specification.new do |spec|
10
10
  spec.name = "dry-logger"
11
- spec.authors = ["Luca Guidi", "Peter Solnica"]
12
- spec.email = ["me@lucaguidi.com", "peter@solnica.online"]
11
+ spec.authors = ["Hanakai team"]
12
+ spec.email = ["info@hanakai.org"]
13
13
  spec.license = "MIT"
14
14
  spec.version = Dry::Logger::VERSION.dup
15
15
 
16
- spec.summary = "Logging for Ruby"
16
+ spec.summary = "Lightweight structured logging for Ruby applications"
17
17
  spec.description = spec.summary
18
18
  spec.homepage = "https://dry-rb.org/gems/dry-logger"
19
19
  spec.files = Dir["CHANGELOG.md", "LICENSE", "README.md", "dry-logger.gemspec", "lib/**/*"]
@@ -21,14 +21,18 @@ Gem::Specification.new do |spec|
21
21
  spec.executables = []
22
22
  spec.require_paths = ["lib"]
23
23
 
24
+ spec.extra_rdoc_files = ["README.md", "CHANGELOG.md", "LICENSE"]
25
+
24
26
  spec.metadata["allowed_push_host"] = "https://rubygems.org"
25
27
  spec.metadata["changelog_uri"] = "https://github.com/dry-rb/dry-logger/blob/main/CHANGELOG.md"
26
28
  spec.metadata["source_code_uri"] = "https://github.com/dry-rb/dry-logger"
27
29
  spec.metadata["bug_tracker_uri"] = "https://github.com/dry-rb/dry-logger/issues"
30
+ spec.metadata["funding_uri"] = "https://github.com/sponsors/hanami"
28
31
 
29
- spec.required_ruby_version = ">= 3.0"
30
-
31
- # to update dependencies edit project.yml
32
+ spec.required_ruby_version = ">= 3.2"
32
33
 
34
+ spec.add_development_dependency "bundler"
35
+ spec.add_development_dependency "rake"
33
36
  spec.add_development_dependency "rspec"
34
37
  end
38
+
@@ -6,7 +6,7 @@ module Dry
6
6
  module Logger
7
7
  # @since 1.0.0
8
8
  # @api private
9
- NEW_LINE = $/ # rubocop:disable Style/SpecialGlobalVars
9
+ NEW_LINE = $/
10
10
 
11
11
  # @since 1.0.0
12
12
  # @api private
@@ -205,13 +205,20 @@ module Dry
205
205
  # @since 1.0.0
206
206
  # @return [true]
207
207
  # @api public
208
- def log(severity, message = nil, **payload, &block)
208
+ def log(severity, message = nil, **payload, &block) # rubocop:disable Metrics/PerceivedComplexity
209
+ return true if LEVELS[severity] < level
210
+
209
211
  case message
210
212
  when Hash then log(severity, **message, &block)
211
213
  else
212
214
  if block
213
215
  progname = message
214
- message = block.call
216
+ block_result = block.call
217
+ case block_result
218
+ when Hash then payload = block_result
219
+ else
220
+ message = block_result
221
+ end
215
222
  end
216
223
  progname ||= id
217
224
 
@@ -226,14 +233,14 @@ module Dry
226
233
 
227
234
  each_backend do |backend|
228
235
  backend.__send__(severity, entry) if backend.log?(entry)
229
- rescue StandardError => e
230
- on_crash.(progname: id, exception: e, message: message, payload: payload)
236
+ rescue StandardError => exception
237
+ on_crash.(progname: id, exception: exception, message: message, payload: payload)
231
238
  end
232
239
  end
233
240
 
234
241
  true
235
- rescue StandardError => e
236
- on_crash.(progname: id, exception: e, message: message, payload: payload)
242
+ rescue StandardError => exception
243
+ on_crash.(progname: id, exception: exception, message: message, payload: payload)
237
244
  true
238
245
  end
239
246
 
@@ -5,18 +5,17 @@ module Dry
5
5
  # Filtering logic
6
6
  # Originaly copied from hanami/utils (see Hanami::Logger)
7
7
  #
8
- # @since 0.1.0
9
8
  # @api private
10
9
  class Filter
11
- # @since 0.1.0
12
10
  # @api private
13
11
  def initialize(filters = [])
14
12
  @filters = filters
15
13
  end
16
14
 
17
- # @since 0.1.0
18
15
  # @api private
19
16
  def call(hash)
17
+ hash = _deep_dup(hash)
18
+
20
19
  _filtered_keys(hash).each do |key|
21
20
  *keys, last = _actual_keys(hash, key.split("."))
22
21
  keys.inject(hash, :fetch)[last] = "[FILTERED]"
@@ -27,12 +26,8 @@ module Dry
27
26
 
28
27
  private
29
28
 
30
- # @since 0.1.0
31
- # @api private
32
29
  attr_reader :filters
33
30
 
34
- # @since 0.1.0
35
- # @api private
36
31
  def _filtered_keys(hash)
37
32
  _key_paths(hash).select { |key|
38
33
  filters.any? { |filter|
@@ -41,22 +36,16 @@ module Dry
41
36
  }
42
37
  end
43
38
 
44
- # @since 0.1.0
45
- # @api private
46
39
  def _key_paths(hash, base = nil)
47
40
  hash.inject([]) do |results, (k, v)|
48
41
  results + (_key_paths?(v) ? _key_paths(v, _build_path(base, k)) : [_build_path(base, k)])
49
42
  end
50
43
  end
51
44
 
52
- # @since 0.1.0
53
- # @api private
54
45
  def _build_path(base, key)
55
46
  [base, key.to_s].compact.join(".")
56
47
  end
57
48
 
58
- # @since 0.1.0
59
- # @api private
60
49
  def _actual_keys(hash, keys)
61
50
  search_in = hash
62
51
 
@@ -70,13 +59,17 @@ module Dry
70
59
  # Check if the given value can be iterated (`Enumerable`) and that isn't a `File`.
71
60
  # This is useful to detect closed `Tempfiles`.
72
61
  #
73
- # @since 0.1.0
74
- # @api private
75
- #
76
62
  # @see https://github.com/hanami/utils/pull/342
77
63
  def _key_paths?(value)
78
64
  value.is_a?(Enumerable) && !value.is_a?(File)
79
65
  end
66
+
67
+ # Returns a deeply duplicated hash to avoid mutations of the original.
68
+ def _deep_dup(hash)
69
+ hash.transform_values { |value|
70
+ value.is_a?(Hash) ? _deep_dup(value) : value
71
+ }
72
+ end
80
73
  end
81
74
  end
82
75
  end
@@ -23,7 +23,7 @@ module Dry
23
23
  # @api 1.0.0
24
24
  # @api private
25
25
  def format_params(value)
26
- return value unless value.empty?
26
+ value unless value.empty?
27
27
  end
28
28
  end
29
29
  end
@@ -1,7 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "set"
4
-
5
3
  require_relative "template"
6
4
  require_relative "structured"
7
5
 
@@ -97,7 +95,7 @@ module Dry
97
95
  def format_exception(value)
98
96
  [
99
97
  "#{value.message} (#{value.class})",
100
- format_backtrace(value.backtrace || EMPTY_BACKTRACE)
98
+ format_backtrace(value.backtrace || EMPTY_ARRAY)
101
99
  ].join(NEW_LINE)
102
100
  end
103
101
 
@@ -140,7 +138,7 @@ module Dry
140
138
  def severity_colors
141
139
  @severity_colors ||= DEFAULT_SEVERITY_COLORS.merge(
142
140
  (options[:severity_colors] || EMPTY_HASH)
143
- .to_h { |key, value| [LEVELS[key.to_s], value] }
141
+ .transform_keys { |key| LEVELS[key.to_s] }
144
142
  )
145
143
  end
146
144
  end
@@ -1,6 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "set"
4
3
  require "dry/logger/constants"
5
4
  require_relative "colors"
6
5
 
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Dry
4
4
  module Logger
5
- VERSION = "1.1.0"
5
+ VERSION = "1.2.0"
6
6
  end
7
7
  end
metadata CHANGED
@@ -1,16 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dry-logger
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.2.0
5
5
  platform: ruby
6
6
  authors:
7
- - Luca Guidi
8
- - Peter Solnica
7
+ - Hanakai team
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2025-04-16 00:00:00.000000000 Z
11
+ date: 2025-11-05 00:00:00.000000000 Z
13
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
14
41
  - !ruby/object:Gem::Dependency
15
42
  name: rspec
16
43
  requirement: !ruby/object:Gem::Requirement
@@ -25,13 +52,15 @@ dependencies:
25
52
  - - ">="
26
53
  - !ruby/object:Gem::Version
27
54
  version: '0'
28
- description: Logging for Ruby
55
+ description: Lightweight structured logging for Ruby applications
29
56
  email:
30
- - me@lucaguidi.com
31
- - peter@solnica.online
57
+ - info@hanakai.org
32
58
  executables: []
33
59
  extensions: []
34
- extra_rdoc_files: []
60
+ extra_rdoc_files:
61
+ - README.md
62
+ - CHANGELOG.md
63
+ - LICENSE
35
64
  files:
36
65
  - CHANGELOG.md
37
66
  - LICENSE
@@ -64,6 +93,7 @@ metadata:
64
93
  changelog_uri: https://github.com/dry-rb/dry-logger/blob/main/CHANGELOG.md
65
94
  source_code_uri: https://github.com/dry-rb/dry-logger
66
95
  bug_tracker_uri: https://github.com/dry-rb/dry-logger/issues
96
+ funding_uri: https://github.com/sponsors/hanami
67
97
  post_install_message:
68
98
  rdoc_options: []
69
99
  require_paths:
@@ -72,7 +102,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
72
102
  requirements:
73
103
  - - ">="
74
104
  - !ruby/object:Gem::Version
75
- version: '3.0'
105
+ version: '3.2'
76
106
  required_rubygems_version: !ruby/object:Gem::Requirement
77
107
  requirements:
78
108
  - - ">="
@@ -82,5 +112,5 @@ requirements: []
82
112
  rubygems_version: 3.3.27
83
113
  signing_key:
84
114
  specification_version: 4
85
- summary: Logging for Ruby
115
+ summary: Lightweight structured logging for Ruby applications
86
116
  test_files: []