Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test against current and next Ruby and Rails versions #335

Merged
merged 19 commits into from
Nov 17, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
57 changes: 57 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
on:
push:
branches: [master]

pull_request:

jobs:
ci:
runs-on: ubuntu-latest
continue-on-error: ${{ endsWith(matrix.ruby, 'head') || matrix.gemfile == 'gemfiles/rails_edge.gemfile' }}

strategy:
matrix:
ruby:
# MRI
- head
- "3.1.0-preview1"
- "3.0"
- "2.7"

# JRuby
- jruby-head
- jruby-9.3
- jruby-9.2

# TruffleRuby
- truffleruby-head
- truffleruby-21.3

gemfile:
- Gemfile
- gemfiles/rails_edge.gemfile
- gemfiles/rails_6.0.gemfile
- gemfiles/rails_5.2.gemfile

# Include additional ruby/gemfile combinations:
include:
# NOTE(ivy): Rails 7 requires Ruby version >= 2.7
- ruby: "2.6"
gemfile: Gemfile
- ruby: "2.6"
gemfile: gemfiles/rails_6.0.gemfile
- ruby: "2.6"
gemfile: gemfiles/rails_5.2.gemfile

env:
BUNDLE_GEMFILE: ${{ github.workspace }}/${{ matrix.gemfile }}

steps:
- uses: actions/checkout@v2

- uses: ruby/setup-ruby@v1
with:
ruby-version: ${{ matrix.ruby }}
bundler-cache: true

- run: bundle exec rake
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
*.gem
.bundle
Gemfile.lock
coverage
gemfiles/*.lock
pkg/*
22 changes: 16 additions & 6 deletions .rubocop.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,25 @@
LineLength:
AllCops:
Exclude:
- Guardfile
- vendor/**/*
NewCops: enable

Layout/LineLength:
Max: 120

Documentation:
Lint/AmbiguousBlockAssociation:
Exclude:
- spec/**/*_spec.rb

Metrics/AbcSize:
Enabled: false

AllCops:
Metrics/BlockLength:
Exclude:
- 'Guardfile'
- spec/**/*_spec.rb

Metrics/AbcSize:
Style/BlockDelimiters:
Enabled: false

Style/EmptyMethod:
Style/Documentation:
Enabled: false
23 changes: 0 additions & 23 deletions .travis.yml

This file was deleted.

7 changes: 5 additions & 2 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

source 'https://rubygems.org'

# Specify your gem's dependencies in lograge.gemspec
Expand All @@ -6,13 +8,14 @@ gemspec
gem 'pry', group: :development

group :test do
gem 'actionpack', '~> 5'
gem 'activerecord', '~> 5'
gem 'actionpack', '~> 6'
gem 'activerecord', '~> 6'
# 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
16 changes: 13 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
[![Build Status](https://travis-ci.org/roidrage/lograge.svg?branch=master)](https://travis-ci.org/roidrage/lograge)
[![.github/workflows/ci.yml](https://github.com/roidrage/lograge/actions/workflows/ci.yml/badge.svg)](https://github.com/roidrage/lograge/actions/workflows/ci.yml)
[![Gem Version](https://badge.fury.io/rb/lograge.svg)](http://badge.fury.io/rb/lograge)

Lograge - Taming Rails' Default Request Logging
=======
# Lograge - Taming Rails' Default Request Logging #

Lograge is an attempt to bring sanity to Rails' noisy and unusable, unparsable
and, in the context of running multiple processes and servers, unreadable
Expand Down Expand Up @@ -45,6 +44,17 @@ relevant information as simple key-value pairs. The syntax is heavily inspired
by the log output of the Heroku router. It doesn't include any timestamp by
default, instead it assumes you use a proper log formatter instead.

## Supported Ruby and Rails Releases ##

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, 6.1, 6.0, 5.2
- Rubies:
- [MRI](https://endoflife.date/ruby): HEAD, 3.1.0-preview1, 3.0, 2.7, 2.6
- JRuby: HEAD, 9.2, 9.1
- TruffleRuby: HEAD, 21.3

## Installation ##

In your Gemfile
Expand Down
4 changes: 3 additions & 1 deletion Rakefile
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'bundler/gem_tasks'

require 'rspec/core/rake_task'
Expand All @@ -7,6 +9,6 @@ require 'rubocop/rake_task'
RuboCop::RakeTask.new

desc 'Run specs, rubocop and reek'
task ci: %w(spec rubocop)
task ci: %w[spec rubocop]

task default: :ci
17 changes: 0 additions & 17 deletions gemfiles/Gemfile.actionpack4.0

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
# frozen_string_literal: true

source 'https://rubygems.org'

# Specify your gem's dependencies in lograge.gemspec
gemspec path: '..'

group :test do
gem 'activerecord', '~> 5.2.0'
gem 'actionpack', '~> 5.2.0'
gem 'activerecord', '~> 5.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
Expand Down
7 changes: 4 additions & 3 deletions gemfiles/Gemfile.actionpack5.0 → gemfiles/rails_6.0.gemfile
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
# frozen_string_literal: true

source 'https://rubygems.org'

# Specify your gem's dependencies in lograge.gemspec
gemspec path: '..'

group :test do
gem 'activerecord', '~> 5.0.0'
gem 'actionpack', '~> 5.0.0'

gem 'actionpack', '~> 6.0.0'
gem 'activerecord', '~> 6.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.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,19 @@
# frozen_string_literal: true

source 'https://rubygems.org'

# Specify your gem's dependencies in lograge.gemspec
gemspec path: '..'

group :test do
gem 'activerecord', '~> 5.1.0'
gem 'actionpack', '~> 5.1.0'

gem 'actionpack', github: 'rails/rails'
gem 'activerecord', github: 'rails/rails'
# 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
11 changes: 6 additions & 5 deletions lib/lograge.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'lograge/version'
require 'lograge/formatters/helpers/method_and_path'
require 'lograge/formatters/cee'
Expand All @@ -17,7 +19,7 @@
require 'active_support/core_ext/module/attribute_accessors'
require 'active_support/core_ext/string/inflections'

# rubocop:disable ModuleLength
# rubocop:disable Metrics/ModuleLength
module Lograge
module_function

Expand Down Expand Up @@ -117,9 +119,7 @@ def unsubscribe(component, subscriber)
events = subscriber.public_methods(false).reject { |method| method.to_s == 'call' }
events.each do |event|
ActiveSupport::Notifications.notifier.listeners_for("#{event}.#{component}").each do |listener|
if listener.instance_variable_get('@delegate') == subscriber
ActiveSupport::Notifications.unsubscribe listener
end
ActiveSupport::Notifications.unsubscribe listener if listener.instance_variable_get('@delegate') == subscriber
end
end
end
Expand Down Expand Up @@ -203,7 +203,7 @@ def keep_original_rails_log
end

def rack_cache_hashlike?(app)
app.config.action_dispatch.rack_cache && app.config.action_dispatch.rack_cache.respond_to?(:[]=)
app.config.action_dispatch.rack_cache&.respond_to?(:[]=)
end
private_class_method :rack_cache_hashlike?

Expand All @@ -223,5 +223,6 @@ def lograge_config
application.config.lograge
end
end
# rubocop:enable Metrics/ModuleLength

require 'lograge/railtie' if defined?(Rails)
2 changes: 2 additions & 0 deletions lib/lograge/formatters/cee.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Lograge
module Formatters
class Cee
Expand Down
18 changes: 5 additions & 13 deletions lib/lograge/formatters/graylog2.rb
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
# frozen_string_literal: true

module Lograge
module Formatters
class Graylog2
include Lograge::Formatters::Helpers::MethodAndPath

def call(data)
# Cloning because we don't want to mess with the original when mutating keys.
data_clone = data.clone

base = {
short_message: short_message(data_clone)
}

# Add underscore to every key to follow GELF additional field syntax.
data_clone.keys.each do |key|
data_clone[underscore_prefix(key)] = data_clone[key]
data_clone.delete(key)
end

data_clone.merge(base)
data.transform_keys { |k| underscore_prefix(k) }.merge(
short_message: short_message(data)
)
end

def underscore_prefix(key)
Expand Down
2 changes: 2 additions & 0 deletions lib/lograge/formatters/helpers/method_and_path.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Lograge
module Formatters
module Helpers
Expand Down
2 changes: 2 additions & 0 deletions lib/lograge/formatters/json.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

require 'json'
module Lograge
module Formatters
Expand Down
2 changes: 2 additions & 0 deletions lib/lograge/formatters/key_value.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
# frozen_string_literal: true

module Lograge
module Formatters
class KeyValue
Expand Down
30 changes: 16 additions & 14 deletions lib/lograge/formatters/l2met.rb
Original file line number Diff line number Diff line change
@@ -1,24 +1,26 @@
# frozen_string_literal: true

require 'lograge/formatters/key_value'

module Lograge
module Formatters
class L2met < KeyValue
L2MET_FIELDS = [
:method,
:path,
:format,
:source,
:status,
:error,
:duration,
:view,
:db,
:location
L2MET_FIELDS = %i[
method
path
format
source
status
error
duration
view
db
location
].freeze

UNWANTED_FIELDS = [
:controller,
:action
UNWANTED_FIELDS = %i[
controller
action
].freeze

def call(data)
Expand Down
Loading