From ad33def7d7b7f15fd5c6c5504aefe3afad0a5a50 Mon Sep 17 00:00:00 2001 From: Petr Heinz Date: Wed, 12 Jul 2023 14:21:37 +0200 Subject: [PATCH] Drop support of Ruby < 2.5 and Rails < 5.0 (#17) --- .github/workflows/main.yml | 91 +------------- README.md | 4 +- gemfiles/rails-3.0.gemfile | 8 -- gemfiles/rails-3.1.gemfile | 8 -- gemfiles/rails-3.2.gemfile | 8 -- gemfiles/rails-4.0.gemfile | 12 -- gemfiles/rails-4.1.gemfile | 12 -- gemfiles/rails-4.2.gemfile | 12 -- lib/logtail-rails/overrides.rb | 1 - .../active_support_3_tagged_logging.rb | 111 ------------------ .../active_support_tagged_logging.rb | 11 +- lib/logtail-rails/version.rb | 2 +- logtail-rails.gemspec | 10 +- 13 files changed, 19 insertions(+), 271 deletions(-) delete mode 100755 gemfiles/rails-3.0.gemfile delete mode 100755 gemfiles/rails-3.1.gemfile delete mode 100755 gemfiles/rails-3.2.gemfile delete mode 100755 gemfiles/rails-4.0.gemfile delete mode 100755 gemfiles/rails-4.1.gemfile delete mode 100755 gemfiles/rails-4.2.gemfile delete mode 100755 lib/logtail-rails/overrides/active_support_3_tagged_logging.rb mode change 100755 => 100644 lib/logtail-rails/overrides/active_support_tagged_logging.rb diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index 64b6610..a92219b 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -19,9 +19,6 @@ jobs: - 2.7.2 - 2.6.6 - 2.5.8 - - 2.4.10 - - 2.3.8 - - 2.2.10 - jruby-9.2.14.0 - truffleruby-21.0.0 gemfile: @@ -36,96 +33,19 @@ jobs: ruby-version: 2.6.6 - gemfile: rails-edge ruby-version: 2.5.8 - - gemfile: rails-edge - ruby-version: 2.4.10 - - gemfile: rails-edge - ruby-version: 2.3.8 - - gemfile: rails-edge - ruby-version: 2.2.10 - gemfile: rails-edge ruby-version: jruby-9.2.14.0 - gemfile: rails-edge ruby-version: truffleruby-21.0.0 - - ruby-version: 3.0.0 - gemfile: rails-5.2 - - ruby-version: 3.0.0 - gemfile: rails-5.1 - - ruby-version: 3.0.0 - gemfile: rails-5.0 - - - gemfile: rails-6.1 - ruby-version: 2.4.10 - - gemfile: rails-6.1 - ruby-version: 2.3.8 - - gemfile: rails-6.1 - ruby-version: 2.2.10 - - gemfile: rails-6.1 - ruby-version: 2.2.10 - - - gemfile: rails-6.0 - ruby-version: 2.4.10 - - gemfile: rails-6.0 - ruby-version: 2.3.8 - - gemfile: rails-6.0 - ruby-version: 2.2.10 - - gemfile: rails-5.2 - ruby-version: 2.2.10 - - env: - BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile - RAILS_ENV: test - - steps: - - uses: actions/checkout@v2 - - - name: Selected Gemfile - run: echo $BUNDLE_GEMFILE - - - name: Set up Ruby ${{ matrix.ruby-version }} - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ matrix.ruby-version }} - bundler-cache: true - - - name: Run tests - run: bundle exec rspec --format documentation - + ruby-version: 3.0.0 - test_bundler_v1: - runs-on: ubuntu-20.04 + - gemfile: rails-5.1 + ruby-version: 3.0.0 - strategy: - fail-fast: false - - matrix: - ruby-version: - - 2.6.6 - - 2.5.8 - - 2.4.10 - - 2.3.8 - - 2.2.10 - gemfile: - - rails-4.2 - - rails-4.1 - - rails-4.0 - - rails-3.2 - - exclude: - - gemfile: rails-4.1 - ruby-version: 2.6.6 - - gemfile: rails-4.1 - ruby-version: 2.5.8 - - gemfile: rails-4.1 - ruby-version: 2.4.10 - - - gemfile: rails-4.0 - ruby-version: 2.6.6 - - gemfile: rails-4.0 - ruby-version: 2.5.8 - - gemfile: rails-4.0 - ruby-version: 2.4.10 + - gemfile: rails-5.0 + ruby-version: 3.0.0 env: BUNDLE_GEMFILE: gemfiles/${{ matrix.gemfile }}.gemfile @@ -140,7 +60,6 @@ jobs: - name: Set up Ruby ${{ matrix.ruby-version }} uses: ruby/setup-ruby@v1 with: - bundler: 1.17 ruby-version: ${{ matrix.ruby-version }} bundler-cache: true diff --git a/README.md b/README.md index 38e1312..4d9cc66 100644 --- a/README.md +++ b/README.md @@ -17,8 +17,8 @@ Collect logs directly from your Ruby on Rails projects. To start logging Ruby pr - Performant, light weight, with a thoughtful design. ### Supported language versions -- Ruby 2.7.0 or newer -- Rails 6.1.4.2 or newer +- Ruby 2.5 or newer +- Rails 5.0 or newer # Installation Install the Logtail Ruby on Rails client library, run the following command: diff --git a/gemfiles/rails-3.0.gemfile b/gemfiles/rails-3.0.gemfile deleted file mode 100755 index 254a205..0000000 --- a/gemfiles/rails-3.0.gemfile +++ /dev/null @@ -1,8 +0,0 @@ -source 'https://rubygems.org' - -gem 'rails', '~> 3.0.0' - -gem 'logtail' -gem 'logtail-rack' - -gemspec :path => '../' diff --git a/gemfiles/rails-3.1.gemfile b/gemfiles/rails-3.1.gemfile deleted file mode 100755 index e7f1abc..0000000 --- a/gemfiles/rails-3.1.gemfile +++ /dev/null @@ -1,8 +0,0 @@ -source 'https://rubygems.org' - -gem 'rails', '~> 3.1.0' - -gem 'logtail' -gem 'logtail-rack' - -gemspec :path => '../' diff --git a/gemfiles/rails-3.2.gemfile b/gemfiles/rails-3.2.gemfile deleted file mode 100755 index defa04d..0000000 --- a/gemfiles/rails-3.2.gemfile +++ /dev/null @@ -1,8 +0,0 @@ -source 'https://rubygems.org' - -gem 'rails', '~> 3.2.0' - -gem 'logtail' -gem 'logtail-rack' - -gemspec :path => '../' diff --git a/gemfiles/rails-4.0.gemfile b/gemfiles/rails-4.0.gemfile deleted file mode 100755 index a69952a..0000000 --- a/gemfiles/rails-4.0.gemfile +++ /dev/null @@ -1,12 +0,0 @@ -source 'https://rubygems.org' - -gem 'rails', '~> 4.0.0' - -gem 'logtail' -gem 'logtail-rack' - -if RUBY_PLATFORM == "java" - gem 'mime-types', '2.6.2' -end - -gemspec :path => '../' diff --git a/gemfiles/rails-4.1.gemfile b/gemfiles/rails-4.1.gemfile deleted file mode 100755 index 9b2294a..0000000 --- a/gemfiles/rails-4.1.gemfile +++ /dev/null @@ -1,12 +0,0 @@ -source 'https://rubygems.org' - -gem 'rails', '~> 4.1.0' - -gem 'logtail' -gem 'logtail-rack' - -if RUBY_PLATFORM == "java" - gem 'mime-types', '2.6.2' -end - -gemspec :path => '../' diff --git a/gemfiles/rails-4.2.gemfile b/gemfiles/rails-4.2.gemfile deleted file mode 100755 index f099c39..0000000 --- a/gemfiles/rails-4.2.gemfile +++ /dev/null @@ -1,12 +0,0 @@ -source 'https://rubygems.org' - -gem 'rails', '~> 4.2.0' - -gem 'logtail' -gem 'logtail-rack' - -if RUBY_PLATFORM == "java" - gem 'mime-types', '2.6.2' -end - -gemspec :path => '../' diff --git a/lib/logtail-rails/overrides.rb b/lib/logtail-rails/overrides.rb index 10f5f35..0e74c6a 100755 --- a/lib/logtail-rails/overrides.rb +++ b/lib/logtail-rails/overrides.rb @@ -1,5 +1,4 @@ # The order is relevant -require "logtail-rails/overrides/active_support_3_tagged_logging" require "logtail-rails/overrides/active_support_tagged_logging" require "logtail-rails/overrides/active_support_buffered_logger" require "logtail-rails/overrides/lograge" diff --git a/lib/logtail-rails/overrides/active_support_3_tagged_logging.rb b/lib/logtail-rails/overrides/active_support_3_tagged_logging.rb deleted file mode 100755 index f2a87f0..0000000 --- a/lib/logtail-rails/overrides/active_support_3_tagged_logging.rb +++ /dev/null @@ -1,111 +0,0 @@ -# Please note, this patch is merely an upgrade, backporting improved tagged logging code -# from newer versions of Rails: -# https://github.com/rails/rails/blob/5-1-stable/activesupport/lib/active_support/tagged_logging.rb -# The behavior of tagged logging will not change in any way. -# -# This patch is specifically for Rails 3. The legacy approach to wrapping the logger in -# ActiveSupport::TaggedLogging is rather poor, hence the reason it was changed entirely -# for Rails 4 and 5. The problem is that ActiveSupport::TaggedLogging is a wrapping -# class that entirely redefines the public API for the logger. As a result, any deviations -# from this API in the logger are not exposed (such as accepting event data as a second argument). -# This is assuming, so we're fixing it here. - -begin - require "active_support/tagged_logging" - - # Instead of patching the class we're pulling the code from Rails master. This brings in - # a number of improvements while also addressing the issue above. - if ActiveSupport::TaggedLogging.instance_of?(Class) - ActiveSupport.send(:remove_const, :TaggedLogging) - - require "active_support/core_ext/module/delegation" - require "active_support/core_ext/object/blank" - require "logger" - - module ActiveSupport - # Wraps any standard Logger object to provide tagging capabilities. - # - # logger = ActiveSupport::TaggedLogging.new(Logger.new(STDOUT)) - # logger.tagged('BCX') { logger.info 'Stuff' } # Logs "[BCX] Stuff" - # logger.tagged('BCX', "Jason") { logger.info 'Stuff' } # Logs "[BCX] [Jason] Stuff" - # logger.tagged('BCX') { logger.tagged('Jason') { logger.info 'Stuff' } } # Logs "[BCX] [Jason] Stuff" - # - # This is used by the default Rails.logger as configured by Railties to make - # it easy to stamp log lines with subdomains, request ids, and anything else - # to aid debugging of multi-user production applications. - module TaggedLogging - module Formatter # :nodoc: - # This method is invoked when a log event occurs. - def call(severity, timestamp, progname, msg) - super(severity, timestamp, progname, "#{tags_text}#{msg}") - end - - def tagged(*tags) - new_tags = push_tags(*tags) - yield self - ensure - pop_tags(new_tags.size) - end - - def push_tags(*tags) - tags.flatten.reject(&:blank?).tap do |new_tags| - current_tags.concat new_tags - end - end - - def pop_tags(size = 1) - current_tags.pop size - end - - def clear_tags! - current_tags.clear - end - - def current_tags - # We use our object ID here to avoid conflicting with other instances - thread_key = @thread_key ||= "activesupport_tagged_logging_tags:#{object_id}".freeze - Thread.current[thread_key] ||= [] - end - - def tags_text - tags = current_tags - if tags.any? - tags.collect { |tag| "[#{tag}] " }.join - end - end - end - - # Simple formatter which only displays the message. - class SimpleFormatter < ::Logger::Formatter - # This method is invoked when a log event occurs - def call(severity, timestamp, progname, msg) - "#{String === msg ? msg : msg.inspect}\n" - end - end - - def self.new(logger) - if logger.respond_to?(:formatter=) && logger.respond_to?(:formatter) - # Ensure we set a default formatter so we aren't extending nil! - logger.formatter ||= SimpleFormatter.new - logger.formatter.extend Formatter - end - - logger.extend(self) - end - - delegate :push_tags, :pop_tags, :clear_tags!, to: :formatter - - def tagged(*tags) - formatter.tagged(*tags) { yield self } - end - - def flush - clear_tags! - super if defined?(super) - end - end - end - end - -rescue Exception -end \ No newline at end of file diff --git a/lib/logtail-rails/overrides/active_support_tagged_logging.rb b/lib/logtail-rails/overrides/active_support_tagged_logging.rb old mode 100755 new mode 100644 index 0afa6d1..4cf91bc --- a/lib/logtail-rails/overrides/active_support_tagged_logging.rb +++ b/lib/logtail-rails/overrides/active_support_tagged_logging.rb @@ -1,10 +1,9 @@ # This is an override instead of an integration because without this Logtail would not # work properly if ActiveSupport::TaggedLogging is used. -# -# This is called after 'active_support_3_tagged_logging' where the constant is loaded and -# replaced. I want to make sure we don't attempt to load it again undoing the patches -# applied there. -if defined?(ActiveSupport::TaggedLogging) + +begin + require "active_support/tagged_logging" + module Logtail module Overrides # @private @@ -63,4 +62,6 @@ def add(severity, message = nil, progname = nil, &block) end end end + +rescue Exception end diff --git a/lib/logtail-rails/version.rb b/lib/logtail-rails/version.rb index a89bd92..cd7d15a 100755 --- a/lib/logtail-rails/version.rb +++ b/lib/logtail-rails/version.rb @@ -1,7 +1,7 @@ module Logtail module Integrations module Rails - VERSION = "0.1.8" + VERSION = "0.2.0" end end end diff --git a/logtail-rails.gemspec b/logtail-rails.gemspec index 8e1848f..ea0f7ab 100644 --- a/logtail-rails.gemspec +++ b/logtail-rails.gemspec @@ -5,14 +5,14 @@ require "logtail-rails/version" Gem::Specification.new do |spec| spec.name = "logtail-rails" spec.version = Logtail::Integrations::Rails::VERSION - spec.authors = ["Logtail"] + spec.authors = ["Better Stack"] spec.email = ["hello@betterstack.com"] spec.summary = %q{Better Stack Rails integration} spec.homepage = "https://github.com/logtail/logtail-ruby-rails" spec.license = "ISC" - spec.required_ruby_version = '>= 2.2.0' + spec.required_ruby_version = '>= 2.5.0' spec.metadata["homepage_uri"] = spec.homepage spec.metadata["source_code_uri"] = "https://github.com/logtail/logtail-ruby-rails" @@ -30,9 +30,9 @@ Gem::Specification.new do |spec| spec.add_runtime_dependency "logtail", "~> 0.1" spec.add_runtime_dependency "logtail-rack", "~> 0.1" - spec.add_runtime_dependency 'activerecord', '>= 3.0.0' - spec.add_runtime_dependency 'railties', '>= 3.0.0' - spec.add_runtime_dependency 'actionpack', '>= 3.0.0' + spec.add_runtime_dependency 'activerecord', '>= 5.0.0' + spec.add_runtime_dependency 'railties', '>= 5.0.0' + spec.add_runtime_dependency 'actionpack', '>= 5.0.0' spec.add_development_dependency "bundler", ">= 0.0"