Skip to content
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
2 changes: 1 addition & 1 deletion .github/workflows/test-external.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ jobs:
- macos

ruby:
- "3.2"
- "3.3"
- "3.4"
- "4.0"

steps:
- uses: actions/checkout@v6
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@ jobs:
- macos

ruby:
- "3.2"
- "3.3"
- "3.4"
- "4.0"

experimental: [false]

Expand Down
1 change: 1 addition & 0 deletions .mailmap
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Yasha Krasnou <yakau.krasnou@44pixels.ai>
19 changes: 19 additions & 0 deletions .rubocop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,25 @@ Layout/SpaceAroundBlockParameters:
Enabled: true
EnforcedStyleInsidePipes: no_space

Layout/FirstArrayElementIndentation:
Enabled: true
EnforcedStyle: consistent

Layout/ArrayAlignment:
Enabled: true
EnforcedStyle: with_fixed_indentation

Layout/FirstArgumentIndentation:
Enabled: true
EnforcedStyle: consistent

Layout/ArgumentAlignment:
Enabled: true
EnforcedStyle: with_fixed_indentation

Layout/ClosingParenthesisIndentation:
Enabled: true

Style/FrozenStringLiteralComment:
Enabled: true

Expand Down
9 changes: 8 additions & 1 deletion bake.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2025, by Samuel Williams.
# Copyright, 2025-2026, by Samuel Williams.

# Update the project documentation with the new version number.
#
Expand All @@ -10,3 +10,10 @@ def after_gem_release_version_increment(version)
context["releases:update"].call(version)
context["utopia:project:update"].call
end

# Create a GitHub release for the given tag.
#
# @parameter tag [String] The tag to create a release for.
def after_gem_release(tag:, **options)
context["releases:github:release"].call(tag)
end
2 changes: 1 addition & 1 deletion config/sus.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2023, by Samuel Williams.
# Copyright, 2023-2026, by Samuel Williams.

require "covered/sus"
include Covered::Sus
6 changes: 3 additions & 3 deletions console-adapter-rails.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ Gem::Specification.new do |spec|
spec.version = Console::Adapter::Rails::VERSION

spec.summary = "Adapt Rails logs and events to the console gem."
spec.authors = ["Samuel Williams", "Joshua Young", "Jun Jiang", "Michael Adams"]
spec.authors = ["Samuel Williams", "Joshua Young", "Jun Jiang", "Michael Adams", "Yasha Krasnou"]
spec.license = "MIT"

spec.cert_chain = ["release.cert"]
Expand All @@ -22,9 +22,9 @@ Gem::Specification.new do |spec|

spec.files = Dir.glob(["{context,lib}/**/*", "*.md"], File::FNM_DOTMATCH, base: __dir__)

spec.required_ruby_version = ">= 3.2"
spec.required_ruby_version = ">= 3.3"

spec.add_dependency "console", "~> 1.21"
spec.add_dependency "console", "~> 1.34"
spec.add_dependency "fiber-storage", "~> 1.0"
spec.add_dependency "rails", ">= 7.0"
end
2 changes: 1 addition & 1 deletion fixtures/app.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2023-2024, by Samuel Williams.
# Copyright, 2023-2026, by Samuel Williams.
# Copyright, 2024, by Michael Adams.

require "rails"
Expand Down
2 changes: 1 addition & 1 deletion gems/rails-v7.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2023-2024, by Samuel Williams.
# Copyright, 2023-2026, by Samuel Williams.

eval_gemfile("../gems.rb")

Expand Down
2 changes: 1 addition & 1 deletion gems/rails-v8.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2023-2024, by Samuel Williams.
# Copyright, 2023-2026, by Samuel Williams.
# Copyright, 2025, by Jun Jiang.

eval_gemfile("../gems.rb")
Expand Down
2 changes: 1 addition & 1 deletion lib/console/adapter/rails.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2023-2024, by Samuel Williams.
# Copyright, 2023-2026, by Samuel Williams.
# Copyright, 2024, by Michael Adams.

require_relative "rails/logger"
Expand Down
21 changes: 20 additions & 1 deletion lib/console/adapter/rails/logger.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
# Released under the MIT License.
# Copyright, 2023-2025, by Samuel Williams.
# Copyright, 2024, by Michael Adams.
# Copyright, 2026, by Yasha Krasnou.

require "console/compatible/logger"

Expand Down Expand Up @@ -83,7 +84,25 @@ def silenced?(severity)
def add(severity, message = nil, progname = nil, &block)
return if silenced?(severity)

super(severity, message, progname, &block)
if formatter.respond_to?(:tag_stack)
tags = formatter.tag_stack.tags

options = tags.each_with_object({}) do |tag, memo|
next unless tag.respond_to?(:to_hash)

tag.to_hash.each do |key, value|
case key
when Symbol
memo[key] = value
else
next unless key.respond_to?(:to_sym)
memo[key.to_sym] = value
end
end
end
end

super(severity, message, progname, **options, &block)
end

# Configure Rails to use the Console logger.
Expand Down
2 changes: 1 addition & 1 deletion lib/console/adapter/rails/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# Released under the MIT License.
# Copyright, 2024, by Michael Adams.
# Copyright, 2024, by Samuel Williams.
# Copyright, 2024-2026, by Samuel Williams.
# Copyright, 2025, by Jun Jiang.

require "action_controller/log_subscriber"
Expand Down
3 changes: 2 additions & 1 deletion license.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# MIT License

Copyright, 2023-2025, by Samuel Williams.
Copyright, 2023-2026, by Samuel Williams.
Copyright, 2023, by Joshua Young.
Copyright, 2024, by Michael Adams.
Copyright, 2025, by Jun Jiang.
Copyright, 2026, by Yasha Krasnou.

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
16 changes: 16 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,22 @@ We welcome contributions to this project.
4. Push to the branch (`git push origin my-new-feature`).
5. Create new Pull Request.

### Running Tests

To run the test suite:

``` shell
bundle exec sus
```

### Making Releases

To make a new release:

``` shell
bundle exec bake gem:release:patch # or minor or major
```

### Developer Certificate of Origin

In order to protect users of this project, we require all contributors to comply with the [Developer Certificate of Origin](https://developercertificate.org/). This ensures that all contributions are properly licensed and attributed.
Expand Down
2 changes: 1 addition & 1 deletion test/console/adapter/rails/action_controller.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2023, by Samuel Williams.
# Copyright, 2023-2026, by Samuel Williams.

require "app"
require "console/capture"
Expand Down
2 changes: 1 addition & 1 deletion test/console/adapter/rails/active_record.rb
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2023-2024, by Samuel Williams.
# Copyright, 2023-2026, by Samuel Williams.
# Copyright, 2024, by Michael Adams.

require "app"
Expand Down
51 changes: 50 additions & 1 deletion test/console/adapter/rails/logger.rb
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
# frozen_string_literal: true

# Released under the MIT License.
# Copyright, 2023-2024, by Samuel Williams.
# Copyright, 2023-2026, by Samuel Williams.
# Copyright, 2024, by Michael Adams.
# Copyright, 2026, by Yasha Krasnou.

require "app"
require "console/capture"
Expand All @@ -21,6 +22,54 @@ def before
expect(Rails.logger).to be(:respond_to?, :tagged)
end

it "should log tags that are Hashes" do
Rails.logger.tagged({ foo: "bar" }) do
Rails.logger.info("Hello World")
end

expect(capture.last).to have_keys(
message: be == "Hello World",
foo: be == "bar"
)
end

it "should not fail when logging string tags" do
Rails.logger.tagged("foo=bar") do
Rails.logger.info("Hello World")
end

expect(capture.last).to have_keys(
message: be == "Hello World"
)

expect(capture.last).not.to have_keys(:foo)
expect(capture.last).not.to have_keys("foo=bar")
end

it "should symbolize string-keyed hash tags" do
Rails.logger.tagged({ "request_id" => "abc" }) do
Rails.logger.info("Hello World")
end

expect(capture.last).to have_keys(
message: be == "Hello World",
request_id: be == "abc"
)
expect(capture.last).not.to have_keys("request_id")
end

it "should symbolize HashWithIndifferentAccess tags" do
Rails.logger.tagged(ActiveSupport::HashWithIndifferentAccess.new(request_id: "xyz")) do
Rails.logger.info("Hello World")
end

expect(capture.last).to have_keys(
message: be == "Hello World",
request_id: be == "xyz"
)
expect(capture.last).not.to have_keys("request_id")
end

it "should support silence" do
expect(Rails.logger).to be(:respond_to?, :silence)

Expand Down
Loading