Skip to content

Commit fcfe123

Browse files
committed
lots of work on homepage
1 parent be7f55e commit fcfe123

File tree

15 files changed

+502
-220
lines changed

15 files changed

+502
-220
lines changed

lib/log_struct/concerns/configuration.rb

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,17 @@ def enabled?
4141
def set_enabled_from_rails_env!
4242
# Set enabled based on current Rails environment and the LOGSTRUCT_ENABLED env var.
4343
# Precedence:
44-
# 1. Check if current Rails environment is in enabled_environments
45-
# 2. Check if LOGSTRUCT_ENABLED env var is set to "true"
44+
# 1. Check if LOGSTRUCT_ENABLED env var is defined
45+
# 2. Check if current Rails environment is in enabled_environments
4646
# 3. Default to whatever is set in config.enabled (which defaults to true)
4747

48-
# First check if current Rails environment is in enabled_environments
49-
rails_env_enabled = config.enabled_environments.include?(::Rails.env.to_sym)
50-
5148
# Then check if LOGSTRUCT_ENABLED env var is set
52-
env_var_enabled = if !rails_env_enabled && ENV["LOGSTRUCT_ENABLED"]
49+
config.enabled = if ENV["LOGSTRUCT_ENABLED"]
5350
# Only override if env var is "true"
5451
ENV["LOGSTRUCT_ENABLED"] == "true"
5552
else
56-
# If rails_env_enabled is true or ENV var is not set, use rails_env_enabled
57-
rails_env_enabled
53+
config.enabled_environments.include?(::Rails.env.to_sym)
5854
end
59-
60-
# Set enabled based on the determined value
61-
config.enabled = env_var_enabled
6255
end
6356

6457
sig { returns(T::Boolean) }

site/app/docs/configuration/page.tsx

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { CodeBlock } from '@/components/code-block';
44
import { HeadingWithAnchor } from '@/components/heading-with-anchor';
55
import Link from 'next/dist/client/link';
66
import { getCodeExample } from '@/lib/codeExamples';
7+
import { Callout } from '@/components/ui/callout';
78

89
export default function ConfigurationPage() {
910
return (
@@ -27,6 +28,50 @@ export default function ConfigurationPage() {
2728

2829
<RubyCodeExample name="basic_configuration" />
2930

31+
<HeadingWithAnchor id="enabling-logstruct">
32+
Enabling LogStruct
33+
</HeadingWithAnchor>
34+
<p className="text-neutral-600 dark:text-neutral-400 mb-4">
35+
LogStruct can be enabled or disabled in the following ways:
36+
</p>
37+
38+
<ul className="list-disc list-inside space-y-2 text-neutral-600 dark:text-neutral-400">
39+
<li>
40+
LogStruct will be <strong>enabled</strong> if the{' '}
41+
<strong>
42+
<code>LOGSTRUCT_ENABLED</code>
43+
</strong>{' '}
44+
environment variable is set to <code>&quot;true&quot;</code>.
45+
</li>
46+
<li>
47+
LogStruct will be <strong>disabled</strong> if{' '}
48+
<strong>
49+
<code>LOGSTRUCT_ENABLED</code>
50+
</strong>{' '}
51+
is set to any other value.
52+
</li>
53+
<li>
54+
If{' '}
55+
<strong>
56+
<code>LOGSTRUCT_ENABLED</code>
57+
</strong>{' '}
58+
is undefined, LogStruct will be <strong>enabled</strong> if the
59+
current Rails environment is listed in{' '}
60+
<code>config.enabled_environments</code>.
61+
</li>
62+
<li>
63+
Finally, you can manually set <code>config.enabled</code> in an
64+
initializer. This will override all other configuration methods.
65+
</li>
66+
</ul>
67+
68+
<p>
69+
First, we check if <code>config.enabled_environments</code> includes the
70+
current Rails environment. If it does, we use that value. Otherwise, we
71+
check the <code>LOGSTRUCT_ENABLED</code> environment variable. If that
72+
is not set, we fall back to <code>config.enabled</code>.
73+
</p>
74+
3075
<HeadingWithAnchor id="environment-configuration">
3176
Environment Configuration
3277
</HeadingWithAnchor>
@@ -57,6 +102,17 @@ export default function ConfigurationPage() {
57102

58103
<RubyCodeExample name="filter_configuration" />
59104

105+
<Callout type="info">
106+
See the{' '}
107+
<Link
108+
href="/docs/filtering-sensitive-data"
109+
className="text-blue-200 hover:text-white"
110+
>
111+
Filtering Sensitive Data
112+
</Link>{' '}
113+
docs for more information.
114+
</Callout>
115+
60116
<HeadingWithAnchor id="error-handling-configuration">
61117
Error Handling Configuration
62118
</HeadingWithAnchor>
@@ -97,8 +153,9 @@ export default function ConfigurationPage() {
97153
Custom Error Reporting
98154
</HeadingWithAnchor>
99155
<p className="text-neutral-600 dark:text-neutral-400 mb-4">
100-
You can customize how errors are reported by implementing your own error
101-
reporting handler:
156+
{/* cspell:ignore doesn */}
157+
If LogStruct doesn&apos;t support your error reporting service, you can
158+
register a custom error reporting handler. (Or submit a PR!)
102159
</p>
103160

104161
<RubyCodeExample name="error_reporting_handler" />

site/app/docs/filtering-sensitive-data/page.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ export default function FilteringSensitiveDataPage() {
1616
still providing useful information for debugging.
1717
</p>
1818

19-
<HeadingWithAnchor id="parameter-filtering" level={2}>
19+
<HeadingWithAnchor id="parameter-filtering" level={1} className="mt-16">
2020
Parameter Filtering
2121
</HeadingWithAnchor>
2222
<p className="text-neutral-600 dark:text-neutral-400 mb-4">

site/app/docs/integrations/page.tsx

Lines changed: 5 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@ import { EditPageLink } from '@/components/edit-page-link';
33
import { RubyCodeExample } from '@/components/ruby-code-example';
44
import { HeadingWithAnchor } from '@/components/heading-with-anchor';
55
import { LogGenerator } from '@/lib/log-generation';
6-
import { LogType, AllLogTypes } from '@/lib/log-generation/log-types';
6+
import { AllLogTypes } from '@/lib/log-generation/log-types';
77
import { getCodeExample } from '@/lib/codeExamples';
8+
import { getLogTypeInfo, getTitleId } from '@/lib/integration-helpers';
89

910
// Helper to format logs as JSON strings for display
1011
// eslint-disable-next-line @typescript-eslint/no-explicit-any
@@ -15,90 +16,6 @@ function formatLog(log: Record<string, any>): string {
1516
// Create a single log generator with a fixed seed for consistent examples
1617
const logGenerator = new LogGenerator(12345);
1718

18-
// Generate information for each log type
19-
function getLogTypeInfo(logType: LogType): {
20-
title: string;
21-
description: string;
22-
configuration_code?: string;
23-
} | null {
24-
switch (logType) {
25-
case LogType.ACTIONMAILER:
26-
return {
27-
title: 'ActionMailer Integration',
28-
description:
29-
"The ActionMailer integration automatically logs email delivery events and handles errors during email delivery. (If you're still on Rails 7.0.x, it also backports delivery callbacks from Rails 7.1.)",
30-
};
31-
32-
case LogType.ACTIVEJOB:
33-
return {
34-
title: 'ActiveJob Integration',
35-
description:
36-
'The ActiveJob integration logs job enqueuing, execution, and completion events with detailed information about the job.',
37-
};
38-
39-
case LogType.ACTIVESTORAGE:
40-
return {
41-
title: 'ActiveStorage Integration',
42-
description:
43-
'The ActiveStorage integration logs uploads, downloads, deletes, and other file operations with detailed information about the file and storage service.',
44-
};
45-
46-
case LogType.CARRIERWAVE:
47-
return {
48-
title: 'CarrierWave Integration',
49-
description:
50-
'The CarrierWave integration adds structured logging for file upload operations, including file metadata and operation duration.',
51-
};
52-
53-
case LogType.REQUEST:
54-
return {
55-
title: 'Request Logs (via Lograge)',
56-
description:
57-
'LogStruct configures Lograge to output request logs in a structured JSON format compatible with the rest of your logs. This includes parameters, response status, controller and action names, and request duration. You can log additional data by configuring a lograge_custom_options handler:',
58-
configuration_code: 'lograge_custom_options',
59-
};
60-
61-
case LogType.SECURITY:
62-
return {
63-
title: 'Security Logging',
64-
description:
65-
'LogStruct includes security-focused logging for Rails applications. This captures security violations like IP spoofing attacks, CSRF token errors, blocked host attempts, and other security-related events.',
66-
};
67-
68-
case LogType.SHRINE:
69-
return {
70-
title: 'Shrine Integration',
71-
description:
72-
'The Shrine integration adds structured logging for file uploads and other Shrine operations, including file metadata and operation duration.',
73-
};
74-
75-
case LogType.SIDEKIQ:
76-
return {
77-
title: 'Sidekiq Integration',
78-
description:
79-
'The Sidekiq integration configures structured JSON logging for Sidekiq worker and client logs, maintaining consistent format with other logs.',
80-
};
81-
82-
case LogType.ERROR:
83-
return {
84-
title: 'Error Handling',
85-
description:
86-
"LogStruct provides structured error logging across your application, capturing error class, message, backtrace, and contextual data for better debugging. (We don't interfere with or replace your existing error reporting library, such as Sentry, Bugsnag, etc.)",
87-
};
88-
89-
case LogType.PLAIN:
90-
// Plain logs are not an integration
91-
return null;
92-
93-
default:
94-
logType satisfies never;
95-
return {
96-
title: 'Unknown Integration',
97-
description: 'No information available for this integration.',
98-
};
99-
}
100-
}
101-
10219
export default function IntegrationsPage() {
10320
return (
10421
<div className="space-y-6">
@@ -121,12 +38,7 @@ export default function IntegrationsPage() {
12138

12239
return (
12340
<div key={logType} className="mt-10">
124-
<HeadingWithAnchor
125-
id={title
126-
.toLowerCase()
127-
.replace(/\s+/g, '-')
128-
.replace(/[^a-z0-9-]/g, '')}
129-
>
41+
<HeadingWithAnchor id={getTitleId(title)}>
13042
{title}
13143
</HeadingWithAnchor>
13244
<p className="text-neutral-600 dark:text-neutral-400 mb-4">
@@ -137,10 +49,7 @@ export default function IntegrationsPage() {
13749
{configuration_code && (
13850
<>
13951
<HeadingWithAnchor
140-
id={`${title
141-
.toLowerCase()
142-
.replace(/\s+/g, '-')
143-
.replace(/[^a-z0-9-]/g, '')}-configuration`}
52+
id={`${getTitleId(title)}-configuration`}
14453
level={2}
14554
className="text-xl font-semibold mt-6 mb-3"
14655
>
@@ -154,10 +63,7 @@ export default function IntegrationsPage() {
15463

15564
{/* Generate a log example for this type */}
15665
<HeadingWithAnchor
157-
id={`${title
158-
.toLowerCase()
159-
.replace(/\s+/g, '-')
160-
.replace(/[^a-z0-9-]/g, '')}-example`}
66+
id={`${getTitleId(title)}-example`}
16167
level={2}
16268
className="text-xl font-semibold mt-6 mb-3"
16369
>

0 commit comments

Comments
 (0)