You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Updated default behavior for when JSON logging is enabled - humans get readable logs, machines get JSON (including test suites on CI to catch bugs early)
Copy file name to clipboardExpand all lines: README.md
+12-5Lines changed: 12 additions & 5 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -6,7 +6,7 @@ We support all your other favorite gems too, like Sidekiq, Sentry, and Shrine. (
6
6
7
7
## Features
8
8
9
-
- JSON logging enabled by default in production and test environments
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)
10
10
- ActionMailer integration for email delivery logging
11
11
- ActiveJob integration for job execution logging
12
12
- Sidekiq integration for background job logging
@@ -58,11 +58,16 @@ Once initialized (and enabled), the gem automatically includes its modules into
58
58
- Rails `config.filter_parameters` are merged into LogStruct's filters and then cleared (to avoid double filtering). Configure sensitive keys via `LogStruct.config.filters`.
59
59
- When `RAILS_LOG_TO_STDOUT` is set, we log to STDOUT only. Otherwise, we log to STDOUT by default without adding a file appender to avoid duplicate logs.
60
60
61
-
### Development behavior
61
+
### Default behavior by process type
62
62
63
-
- Disabled by default in development. Enable explicitly via `LOGSTRUCT_ENABLED=true` or `LogStruct.configure { |c| c.enabled = true }`.
64
-
- When enabled in development, LogStruct now defaults to production‑style JSON output so you can preview exactly what will be shipped in prod.
65
-
- You can opt back into the colorful human formatter with:
63
+
-**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
66
+
-**Console** (`rails console`): JSON logging is disabled by default in all environments, providing human-readable logs instead
67
+
-**Other Rake tasks** (`rake db:migrate`, etc.): JSON logging is disabled by default in production, providing human-readable logs instead
68
+
-**Development environment**: Disabled by default for all process types. Enable explicitly via `LOGSTRUCT_ENABLED=true` or `LogStruct.configure { |c| c.enabled = true }`.
69
+
70
+
When enabled in development, LogStruct defaults to production‑style JSON output so you can preview exactly what will be shipped in prod. You can opt back into the colorful human formatter with:
66
71
67
72
```ruby
68
73
LogStruct.configure do |c|
@@ -71,6 +76,8 @@ LogStruct.configure do |c|
71
76
end
72
77
```
73
78
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.
80
+
74
81
## Documentation
75
82
76
83
Please see the [documentation](https://logstruct.com/docs) for more details. (All code examples are type-checked and tested, and it's harder to keep a README up to date.)
Set <code>LOGSTRUCT_ENABLED=true</code> to force JSON logs, or{' '}
78
+
<code>LOGSTRUCT_ENABLED=false</code> to disable completely.
79
+
<divclassName="mt-2">
80
+
<CodeBlocklanguage="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`}
82
+
</CodeBlock>
83
+
</div>
84
+
</li>
85
+
<li>
86
+
<strong>Initializer configuration</strong>
87
+
<br/>
88
+
Manually set <code>config.enabled = true</code> in your initializer to
89
+
enable in all development processes.
90
+
<divclassName="mt-2">
91
+
<CodeBlocklanguage="ruby">
92
+
{`LogStruct.configure do |c|\n c.enabled = true\nend`}
93
+
</CodeBlock>
94
+
</div>
95
+
</li>
96
+
<li>
97
+
<strong>Environment list</strong>
98
+
<br/>
99
+
Modify <code>config.enabled_environments</code> to change which
100
+
environments have JSON logs by default (currently{' '}
101
+
<code>[:test, :production]</code>).
102
+
</li>
103
+
</ol>
104
+
105
+
<Callouttype="info">
106
+
The <code>CI</code> environment variable is automatically detected by
107
+
most CI systems (GitHub Actions, GitLab CI, CircleCI, Travis, etc.). If
108
+
your CI doesn't set it, add <code>CI=true</code> to your CI
109
+
configuration.
110
+
</Callout>
111
+
76
112
<HeadingWithAnchorid="environment-configuration">
77
113
Environment Configuration
78
114
</HeadingWithAnchor>
@@ -118,6 +154,16 @@ end`}
118
154
<code>config.enabled_environments</code>.
119
155
</Callout>
120
156
157
+
<Callouttype="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{' '}
160
+
<code>LOGSTRUCT_ENABLED=true</code> when running the command:
{`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.`}
0 commit comments