diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 74d3364..eb5d8f0 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -29,7 +29,7 @@ jobs: ruby: '2.7' steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v4 - name: Set up Ruby uses: ruby/setup-ruby@v1 with: diff --git a/.rubocop.yml b/.rubocop.yml index 174f700..544ed9c 100644 --- a/.rubocop.yml +++ b/.rubocop.yml @@ -14,16 +14,20 @@ AllCops: # - 'vendor/bundle/**/*' -Lint/ConstantDefinitionInBlock: - Exclude: - - 'spec/**/*' - Layout/ArgumentAlignment: EnforcedStyle: with_fixed_indentation Layout/FirstHashElementIndentation: EnforcedStyle: consistent +Lint/ConstantDefinitionInBlock: + Exclude: + - 'spec/**/*' + +Lint/StructNewOverride: + Exclude: + - spec/lib/lorekeeper/backtrace_cleaner_spec.rb + Metrics/ParameterLists: CountKeywordArgs: false diff --git a/CHANGELOG.md b/CHANGELOG.md index 561c060..31d58b0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,6 @@ +# 2.6.3 +* Fix Lorekeeper::BacktraceCleaner to support BacktraceLocation + # 2.6.2 * Fix respond_to? method signature diff --git a/lib/lorekeeper/backtrace_cleaner.rb b/lib/lorekeeper/backtrace_cleaner.rb index e9fd029..b072f90 100644 --- a/lib/lorekeeper/backtrace_cleaner.rb +++ b/lib/lorekeeper/backtrace_cleaner.rb @@ -38,6 +38,7 @@ def filter_rails_root_backtrace(backtrace) last_index = nil result = [] backtrace.each_with_index do |line, idx| + line = line.to_s if line.start_with?(@rails_root) && @gem_path.none? { |path| line.start_with?(path) } result << line[@rails_root_size..] last_index = idx diff --git a/lib/lorekeeper/json_logger.rb b/lib/lorekeeper/json_logger.rb index 183fe9b..16c4636 100644 --- a/lib/lorekeeper/json_logger.rb +++ b/lib/lorekeeper/json_logger.rb @@ -28,10 +28,10 @@ def reset_state # Delegates methods to the existing Logger instance # We are extending the logger API with methods error_with_data, etc LOGGING_METHODS.each do |method_name| - define_method "#{method_name}_with_data", ->(message_param = nil, data = {}, &block) { + define_method :"#{method_name}_with_data", ->(message_param = nil, data = {}, &block) { return true if METHOD_SEVERITY_MAP[method_name] < @level - extra_fields = { DATA => (data || {}) } + extra_fields = { DATA => data || {} } with_extra_fields(extra_fields) do add(METHOD_SEVERITY_MAP[method_name], message_param, nil, &block) end @@ -87,7 +87,7 @@ def exception(exception, custom_message = nil, custom_data = nil, custom_level = else log_data(METHOD_SEVERITY_MAP[:warn], 'Logger exception called without exception class.') message = "#{exception.class}: #{exception.inspect} #{param_message}" - with_extra_fields(DATA => (param_data || {})) { log_data(log_level, message) } + with_extra_fields(DATA => param_data || {}) { log_data(log_level, message) } end end diff --git a/lib/lorekeeper/simple_logger.rb b/lib/lorekeeper/simple_logger.rb index 09fb262..16e2f11 100644 --- a/lib/lorekeeper/simple_logger.rb +++ b/lib/lorekeeper/simple_logger.rb @@ -38,7 +38,7 @@ def inspect # Extending the logger API with methods error_with_data, etc LOGGING_METHODS.each do |method_name| - define_method "#{method_name}_with_data", ->(message_param = nil, data = {}) { + define_method :"#{method_name}_with_data", ->(message_param = nil, data = {}) { return true if METHOD_SEVERITY_MAP[method_name] < @level log_data(METHOD_SEVERITY_MAP[method_name], "#{message_param}, data: #{data}") diff --git a/lib/lorekeeper/version.rb b/lib/lorekeeper/version.rb index 033f04a..0a2654b 100644 --- a/lib/lorekeeper/version.rb +++ b/lib/lorekeeper/version.rb @@ -1,5 +1,5 @@ # frozen_string_literal: true module Lorekeeper - VERSION = '2.6.2' + VERSION = '2.6.3' end diff --git a/spec/lib/lorekeeper/backtrace_cleaner_spec.rb b/spec/lib/lorekeeper/backtrace_cleaner_spec.rb index c884adc..fa21adb 100644 --- a/spec/lib/lorekeeper/backtrace_cleaner_spec.rb +++ b/spec/lib/lorekeeper/backtrace_cleaner_spec.rb @@ -45,11 +45,13 @@ "/home/app/web/vendor/bundle/ruby/2.7.0/bin/rake:25:in `load'" ] end + let(:new_backtrace_location) { new_backtrace.map { |bt| BacktraceLocation.new('', '', bt) } } before do allow(Gem).to receive(:path).and_return(['/ruby/2.5.0', '/home/app/web/vendor/bundle/ruby/2.7.0']) stub_const('RbConfig::CONFIG', { 'rubylibdir' => '/usr/local/rvm/rubies/ruby-2.7.6/lib/ruby/2.7.0' }) stub_const('Rails', double(root: '/home/app/web')) + stub_const('BacktraceLocation', Struct.new(:path, :lineno, :to_s)) # https://github.com/rails/rails/blob/v7.1.2/activesupport/lib/active_support/syntax_error_proxy.rb#L15 end context 'Logging just an exception' do @@ -75,11 +77,17 @@ ActiveSupport::VERSION::MAJOR < 6 ? active_support_exception_less_than_v6 : active_support_exception_v6 end - it 'Does not log the lines matched with the denylist' do + it 'does not log the lines matched with the denylist' do expect(instance.clean(new_backtrace)).to eq(no_noise_backtrace) end - it 'Logs all backtraces when ActiveSupport::BacktraceCleaner and Rails.root are not defined' do + context 'with backtrace location' do + it 'does not log the lines matched with the denylist' do + expect(instance.clean(new_backtrace_location)).to eq(no_noise_backtrace) + end + end + + it 'logs all backtraces when ActiveSupport::BacktraceCleaner and Rails.root are not defined' do hide_const('ActiveSupport::BacktraceCleaner') hide_const('Rails') diff --git a/spec/lib/lorekeeper/json_logger_spec.rb b/spec/lib/lorekeeper/json_logger_spec.rb index 90850a3..e641577 100644 --- a/spec/lib/lorekeeper/json_logger_spec.rb +++ b/spec/lib/lorekeeper/json_logger_spec.rb @@ -37,7 +37,7 @@ expect(io.received_message.keys[0..2]).to eq(%w[timestamp message level]) end it "Outputs the correct format for #{method}_with_data" do - logger.send("#{method}_with_data", message, data) + logger.send(:"#{method}_with_data", message, data) expect(io.received_message).to eq(expected_data.merge('level' => level_name.call(method))) end end @@ -396,7 +396,7 @@ end it "No data is written to the device for #{method}_with_data" do expect(io).not_to receive(:write) - logger.send("#{method}_with_data", message, data) + logger.send(:"#{method}_with_data", message, data) end end end diff --git a/spec/lib/lorekeeper/multi_logger_spec.rb b/spec/lib/lorekeeper/multi_logger_spec.rb index b43904a..43e51a5 100644 --- a/spec/lib/lorekeeper/multi_logger_spec.rb +++ b/spec/lib/lorekeeper/multi_logger_spec.rb @@ -40,7 +40,7 @@ logger.add_logger(json_logger) Lorekeeper::FastLogger::LOGGING_METHODS.each do |log_level| - logger.send("#{log_level}_with_data", message, { sum: 123 }) + logger.send(:"#{log_level}_with_data", message, { sum: 123 }) expect(io.received_message).to include("#{message}, data: {:sum=>123}") expect(json_io.received_message).to include(