diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e11aa630..00046e6b 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -21,6 +21,7 @@ jobs: - "3.1" - "3.2" - "3.3" + - "3.4" # JRuby - jruby-9.3 @@ -31,7 +32,9 @@ jobs: gemfile: - Gemfile - - gemfiles/rails_edge.gemfile # 7.2.0.alpha + - gemfiles/rails_edge.gemfile # 8.1 + - gemfiles/rails_8.0.gemfile + - gemfiles/rails_7.2.gemfile - gemfiles/rails_7.1.gemfile - gemfiles/rails_7.0.gemfile - gemfiles/rails_6.1.gemfile @@ -51,21 +54,51 @@ jobs: # NOTE(ivy): Rails 7 requires Ruby version >= 2.7 - ruby: jruby-9.3 gemfile: gemfiles/rails_edge.gemfile + - ruby: jruby-9.3 + gemfile: gemfiles/rails_7.2.gemfile - ruby: jruby-9.3 gemfile: gemfiles/rails_7.1.gemfile - ruby: jruby-9.3 gemfile: gemfiles/rails_7.0.gemfile - ruby: jruby-9.2 gemfile: gemfiles/rails_edge.gemfile + - ruby: jruby-9.2 + gemfile: gemfiles/rails_7.2.gemfile - ruby: jruby-9.2 gemfile: gemfiles/rails_7.1.gemfile - ruby: jruby-9.2 gemfile: gemfiles/rails_7.0.gemfile - # NOTE: Rails edge requires Ruby version >= 3.1 + # NOTE: Rails 7.2 requires Ruby version >= 3.1 + - ruby: "2.7" + gemfile: gemfiles/rails_7.2.gemfile + - ruby: "3.0" + gemfile: gemfiles/rails_7.2.gemfile + # NOTE: Rails 8.0 edge requires Ruby version >= 3.2 + - ruby: "2.7" + gemfile: gemfiles/rails_8.0.gemfile + - ruby: "3.0" + gemfile: gemfiles/rails_8.0.gemfile + - ruby: "3.1" + gemfile: gemfiles/rails_8.0.gemfile + - ruby: jruby-9.3 + gemfile: gemfiles/rails_8.0.gemfile + - ruby: jruby-9.4 + gemfile: gemfiles/rails_8.0.gemfile + - ruby: truffleruby-23.0 + gemfile: gemfiles/rails_8.0.gemfile + # NOTE: Rails edge requires Ruby version >= 3.2 - ruby: "2.7" gemfile: gemfiles/rails_edge.gemfile - ruby: "3.0" gemfile: gemfiles/rails_edge.gemfile + - ruby: "3.1" + gemfile: gemfiles/rails_edge.gemfile + - ruby: jruby-9.3 + gemfile: gemfiles/rails_edge.gemfile + - ruby: jruby-9.4 + gemfile: gemfiles/rails_edge.gemfile + - ruby: truffleruby-23.0 + gemfile: gemfiles/rails_edge.gemfile env: diff --git a/.gitignore b/.gitignore index 58f437c2..a4687217 100644 --- a/.gitignore +++ b/.gitignore @@ -3,5 +3,6 @@ Gemfile.lock coverage gemfiles/*.lock +gemfiles/vendor pkg/* vendor/bundle \ No newline at end of file diff --git a/Gemfile b/Gemfile index 85c26f57..b4e778a3 100644 --- a/Gemfile +++ b/Gemfile @@ -18,4 +18,8 @@ group :test do gem 'jrjackson', '~> 0.2.9', platforms: :jruby gem 'lines' gem 'thread_safe' + + # Since Ruby-3.4 vendored stdlib logger warns that it will be removed + # Since Ruby-3.5 logger is extracted into a standalone gem + gem 'logger' end diff --git a/README.md b/README.md index 1e6d4289..1d368793 100644 --- a/README.md +++ b/README.md @@ -49,9 +49,9 @@ default, instead it assumes you use a proper log formatter instead. Lograge is actively tested against current and officially supported Ruby and Rails releases. That said, Lograge _should_ work with older releases. -- [Rails](https://endoflife.date/rails): Edge, 7.1, 7.0, 6.1, 6.0, 5.2 +- [Rails](https://endoflife.date/rails): Edge, 8.0, 7.2, 7.1, 7.0, 6.1, 6.0, 5.2 - Rubies: - - [MRI](https://endoflife.date/ruby): HEAD, 3.3, 3.2 3.1, 3.0, 2.7, 2.6 + - [MRI](https://endoflife.date/ruby): HEAD, 3.4, 3.3, 3.2 3.1, 3.0, 2.7, 2.6 - JRuby: HEAD, 9.2, 9.1 - TruffleRuby: HEAD, 21.3 diff --git a/gemfiles/rails_7.2.gemfile b/gemfiles/rails_7.2.gemfile new file mode 100644 index 00000000..a451a5c4 --- /dev/null +++ b/gemfiles/rails_7.2.gemfile @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +source 'https://rubygems.org' + +# Specify your gem's dependencies in lograge.gemspec +gemspec path: '..' + +group :test do + gem 'actionpack', '~> 7.2.0' + gem 'activerecord', '~> 7.2.0' + # logstash does not release any gems on rubygems, but they have two gemspecs within their repo. + # Using the tag is an attempt of having a stable version to test against where we can ensure that + # we test against the correct code. + gem 'logstash-event', git: 'https://github.com/elastic/logstash', tag: 'v1.5.4' + # logstash 1.5.4 is only supported with jrjackson up to 0.2.9 + gem 'jrjackson', '~> 0.2.9', platforms: :jruby + gem 'lines' + gem 'thread_safe' +end diff --git a/gemfiles/rails_8.0.gemfile b/gemfiles/rails_8.0.gemfile new file mode 100644 index 00000000..63d64639 --- /dev/null +++ b/gemfiles/rails_8.0.gemfile @@ -0,0 +1,19 @@ +# frozen_string_literal: true + +source 'https://rubygems.org' + +# Specify your gem's dependencies in lograge.gemspec +gemspec path: '..' + +group :test do + gem 'actionpack', '~> 8.0.0' + gem 'activerecord', '~> 8.0.0' + # logstash does not release any gems on rubygems, but they have two gemspecs within their repo. + # Using the tag is an attempt of having a stable version to test against where we can ensure that + # we test against the correct code. + gem 'logstash-event', git: 'https://github.com/elastic/logstash', tag: 'v1.5.4' + # logstash 1.5.4 is only supported with jrjackson up to 0.2.9 + gem 'jrjackson', '~> 0.2.9', platforms: :jruby + gem 'lines' + gem 'thread_safe' +end diff --git a/lib/lograge.rb b/lib/lograge.rb index 7ac247ac..7e31653a 100644 --- a/lib/lograge.rb +++ b/lib/lograge.rb @@ -1,5 +1,6 @@ # frozen_string_literal: true +require 'logger' require 'lograge/version' require 'lograge/formatters/helpers/method_and_path' require 'lograge/formatters/cee' diff --git a/lograge.gemspec b/lograge.gemspec index 1cd24598..bb476dec 100644 --- a/lograge.gemspec +++ b/lograge.gemspec @@ -28,8 +28,8 @@ Gem::Specification.new do |s| s.add_development_dependency 'rubocop', '~> 1.23' s.add_development_dependency 'simplecov', '~> 0.21' - s.add_runtime_dependency 'actionpack', '>= 4' - s.add_runtime_dependency 'activesupport', '>= 4' - s.add_runtime_dependency 'railties', '>= 4' - s.add_runtime_dependency 'request_store', '~> 1.0' + s.add_dependency 'actionpack', '>= 4' + s.add_dependency 'activesupport', '>= 4' + s.add_dependency 'railties', '>= 4' + s.add_dependency 'request_store', '~> 1.0' end diff --git a/spec/log_subscribers/action_cable_spec.rb b/spec/log_subscribers/action_cable_spec.rb index c1a6c631..0dfa3856 100644 --- a/spec/log_subscribers/action_cable_spec.rb +++ b/spec/log_subscribers/action_cable_spec.rb @@ -33,20 +33,20 @@ context 'with custom_options configured for cee output' do before do - Lograge.formatter = ->(data) { "My test: #{data}" } + Lograge.formatter = ->(data) { "My test: #{data.to_json}" } end it 'combines the hash properly for the output' do Lograge.custom_options = { data: 'value' } subscriber.perform_action(event) - expect(log_output.string).to match(/^My test: {.*:data=>"value"/) + expect(log_output.string).to match(/^My test: {.*"data"\s*:\s*"value"/) end it 'combines the output of a lambda properly' do Lograge.custom_options = ->(_event) { { data: 'value' } } subscriber.perform_action(event) - expect(log_output.string).to match(/^My test: {.*:data=>"value"/) + expect(log_output.string).to match(/^My test: {.*"data"\s*:\s*"value"/) end it 'works when the method returns nil' do diff --git a/spec/log_subscribers/action_controller_spec.rb b/spec/log_subscribers/action_controller_spec.rb index f272fad5..35e60ec5 100644 --- a/spec/log_subscribers/action_controller_spec.rb +++ b/spec/log_subscribers/action_controller_spec.rb @@ -39,20 +39,20 @@ context 'with custom_options configured for cee output' do before do - Lograge.formatter = ->(data) { "My test: #{data}" } + Lograge.formatter = ->(data) { "My test: #{data.to_json}" } end it 'combines the hash properly for the output' do Lograge.custom_options = { data: 'value' } subscriber.process_action(event) - expect(log_output.string).to match(/^My test: {.*:data=>"value"/) + expect(log_output.string).to match(/^My test: {.*"data"\s*:\s*"value"/) end it 'combines the output of a lambda properly' do Lograge.custom_options = ->(_event) { { data: 'value' } } subscriber.process_action(event) - expect(log_output.string).to match(/^My test: {.*:data=>"value"/) + expect(log_output.string).to match(/^My test: {.*"data"\s*:\s*"value"/) end it 'works when the method returns nil' do