Skip to content

Commit 9fc6c5f

Browse files
ndbroadbentclaude
andcommitted
Change storage/queue/format fields to Symbol and enable JSON logging for all test runs
Breaking changes for v0.1.3: - Changed storage, queue_name, and format fields from String to Symbol type to match Rails conventions - JSON logging now enabled for all test runs (both local and CI) to ensure tests catch production bugs This ensures local tests match CI behavior and catch serialization issues early. Updated all schemas, regenerated log structs, fixed Sorbet type errors in tests, and updated documentation. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
1 parent d524060 commit 9fc6c5f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+138
-114
lines changed

.rubocop.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,8 @@ Sorbet/TrueSigil:
104104
- 'scripts/**/*.rb'
105105
Exclude:
106106
- 'scripts/test.rb' # Has dynamic code that Sorbet can't handle
107+
- 'test/log_struct/formatter_test.rb' # Metaprogramming-heavy, uses typed: false
108+
- 'test/log_struct/rails_boot_banner_silencer_test.rb' # Metaprogramming-heavy, uses typed: false
107109
SuggestedStrictness: true
108110

109111
# Don't try to validate typing on generated Sorbet RBI files

CHANGELOG.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,20 @@ All notable changes to this project will be documented in this file.
55
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
66
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
77

8+
## [0.1.3] - 2025-10-04
9+
10+
### Changed
11+
12+
- **Fix**: Changed storage, queue name, and format fields from `String` to `Symbol` type to match Rails conventions
13+
- Affected log types: ActiveStorage, CarrierWave, Shrine (storage field), ActiveJob, GoodJob (queue_name field), Request (format field)
14+
- JSON logging now enabled for all test runs (both local and CI) to ensure tests catch production bugs
15+
- Previously only enabled for CI test runs, now always enabled in test environment
16+
- This ensures local tests match CI behavior and catch serialization issues early
17+
818
## [0.1.2] - 2025-10-03
919

1020
Better default policy for when JSON logs are enabled: machines get JSON, humans get readable logs.
11-
Enable LogStruct for production servers or when running tests on CI.
21+
Enable LogStruct for production servers and test runs (both local and CI) to ensure tests catch production bugs.
1222
Keep dev-friendly logging on local machines or when running interactive commands on production servers.
1323

1424
## [0.1.1] - 2025-09-29

README.md

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ We support all your other favorite gems too, like Sidekiq, Sentry, and Shrine. (
66

77
## Features
88

9-
- JSON logging enabled by default for server processes in production and test environments, and for CI test runs (automatically disabled for console, local tests, and other Rake tasks)
9+
- JSON logging enabled by default for server processes in production and test environments (automatically disabled for console and other Rake tasks)
1010
- ActionMailer integration for email delivery logging
1111
- ActiveJob integration for job execution logging
1212
- Sidekiq integration for background job logging
@@ -61,8 +61,7 @@ Once initialized (and enabled), the gem automatically includes its modules into
6161
### Default behavior by process type
6262

6363
- **Server processes** (`rails server`): JSON logging is enabled by default in production and test environments
64-
- **CI test runs** (`rails test` when `CI=true`): JSON logging is enabled by default to catch production bugs in your automated tests
65-
- **Local test runs** (`rails test` locally): JSON logging is disabled by default, providing human-readable logs for debugging
64+
- **Test runs** (`rails test`): JSON logging is enabled by default in test environment to ensure tests catch production bugs
6665
- **Console** (`rails console`): JSON logging is disabled by default in all environments, providing human-readable logs instead
6766
- **Other Rake tasks** (`rake db:migrate`, etc.): JSON logging is disabled by default in production, providing human-readable logs instead
6867
- **Development environment**: Disabled by default for all process types. Enable explicitly via `LOGSTRUCT_ENABLED=true` or `LogStruct.configure { |c| c.enabled = true }`.
@@ -76,7 +75,7 @@ LogStruct.configure do |c|
7675
end
7776
```
7877

79-
To force JSON logs in console, local test runs, or other Rake tasks (e.g., for debugging), set `LOGSTRUCT_ENABLED=true` in your environment.
78+
To force JSON logs in console or other Rake tasks (e.g., for debugging), set `LOGSTRUCT_ENABLED=true` in your environment.
8079

8180
## Documentation
8281

docs/app/docs/configuration/page.tsx

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,8 @@ export default function ConfigurationPage() {
4444
analysis)
4545
</li>
4646
<li>
47-
<strong>CI test runs</strong> → JSON logs (to catch production bugs)
47+
<strong>Test runs</strong> → JSON logs (to catch production bugs in
48+
both local and CI environments)
4849
</li>
4950
<li>
5051
<strong>Local development</strong> → Human-readable logs (disabled by
@@ -56,9 +57,6 @@ export default function ConfigurationPage() {
5657
<li>
5758
<strong>Rake tasks</strong> → Human-readable logs
5859
</li>
59-
<li>
60-
<strong>Local test runs</strong> → Human-readable logs (for debugging)
61-
</li>
6260
</ul>
6361

6462
<HeadingWithAnchor id="overriding-defaults" level={3}>
@@ -78,7 +76,7 @@ export default function ConfigurationPage() {
7876
<code>LOGSTRUCT_ENABLED=false</code> to disable completely.
7977
<div className="mt-2">
8078
<CodeBlock language="bash">
81-
{`# Force JSON logs in console for debugging\nLOGSTRUCT_ENABLED=true rails console\n\n# Force JSON logs in local tests\nLOGSTRUCT_ENABLED=true rails test`}
79+
{`# Force JSON logs in console for debugging\nLOGSTRUCT_ENABLED=true rails console\n\n# Disable JSON logs in tests (not recommended)\nLOGSTRUCT_ENABLED=false rails test`}
8280
</CodeBlock>
8381
</div>
8482
</li>
@@ -155,13 +153,13 @@ end`}
155153
</Callout>
156154

157155
<Callout type="info">
158-
To force JSON logs in console, local test runs, or other Rake tasks
159-
(e.g., for debugging or inspecting the exact JSON output), set{' '}
156+
To force JSON logs in console or other Rake tasks (e.g., for debugging
157+
or inspecting the exact JSON output), set{' '}
160158
<code>LOGSTRUCT_ENABLED=true</code> when running the command:
161159
<br />
162160
<code>LOGSTRUCT_ENABLED=true rails console</code>
163161
<br />
164-
<code>LOGSTRUCT_ENABLED=true rails test</code>
162+
<code>LOGSTRUCT_ENABLED=true rake db:migrate</code>
165163
</Callout>
166164

167165
<HeadingWithAnchor id="integration-configuration">

docs/app/docs/getting-started/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export default function GettingStartedPage() {
2929
<CodeBlock language="bash">bundle install</CodeBlock>
3030

3131
<p className="text-neutral-600 dark:text-neutral-300 mt-6">
32-
{`LogStruct is now installed and will automatically enable JSON structured logging for server processes in the test and production environments, and for CI test runs. Console, local tests, and other Rake tasks will use human-readable logs by default.`}
32+
{`LogStruct is now installed and will automatically enable JSON structured logging for test runs and server processes in production environments. Console and other Rake tasks will use human-readable logs by default.`}
3333
</p>
3434

3535
<HeadingWithAnchor id="basic-configuration" level={2}>

docs/app/docs/page.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ export default function DocsPage() {
2222
</HeadingWithAnchor>
2323
<ul className="list-disc list-inside space-y-2 text-neutral-600 dark:text-neutral-300">
2424
<li>
25-
JSON logging enabled by default for server processes in production and
26-
test environments, and for CI test runs (automatically disabled for
27-
console, local tests, and other Rake tasks).
25+
JSON logging enabled by default for server processes and test runs in
26+
production and test environments (automatically disabled for console
27+
and other Rake tasks).
2828
</li>
2929
<li>
3030
Sets up <a href="https://github.com/roidrage/lograge">Lograge</a> for

lib/log_struct/concerns/configuration.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,10 @@ def set_enabled_from_rails_env!
6060
else
6161
is_console = console_process?
6262
is_server = server_process?
63-
is_ci = ci_build?
63+
ci_build?
6464
in_enabled_env = config.enabled_environments.include?(::Rails.env.to_sym)
6565

66-
in_enabled_env && !is_console && (is_server || (::Rails.env.test? && is_ci))
66+
in_enabled_env && !is_console && (is_server || ::Rails.env.test?)
6767
end
6868
end
6969

lib/log_struct/integrations/good_job/log_subscriber.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -146,7 +146,7 @@ def build_base_fields(job, payload)
146146
Log::GoodJob::BaseFields.new(
147147
job_id: job&.job_id,
148148
job_class: job&.job_class,
149-
queue_name: job&.queue_name,
149+
queue_name: job&.queue_name&.to_sym,
150150
arguments: job&.arguments,
151151
executions: execution&.executions
152152
)

lib/log_struct/integrations/lograge.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ def configure_lograge(logstruct_config)
5050
Log::Request.new(
5151
http_method: data[:method]&.to_s,
5252
path: data[:path]&.to_s,
53-
format: data[:format]&.to_s,
53+
format: data[:format]&.to_sym,
5454
controller: data[:controller]&.to_s,
5555
action: data[:action]&.to_s,
5656
status: status,

lib/log_struct/log/active_job.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ class BaseFields < T::Struct
1818
extend T::Sig
1919
const :job_id, String
2020
const :job_class, String
21-
const :queue_name, T.nilable(String), default: nil
21+
const :queue_name, T.nilable(Symbol), default: nil
2222
const :arguments, T.nilable(T::Array[T.untyped]), default: nil
2323
const :executions, T.nilable(Integer), default: nil
2424
const :provider_job_id, T.nilable(String), default: nil
@@ -27,7 +27,7 @@ class BaseFields < T::Struct
2727
{
2828
job_id: String,
2929
job_class: String,
30-
queue_name: T.nilable(String),
30+
queue_name: T.nilable(Symbol),
3131
arguments: T.nilable(T::Array[T.untyped]),
3232
executions: T.nilable(Integer),
3333
provider_job_id: T.nilable(String)

0 commit comments

Comments
 (0)