@@ -2,22 +2,16 @@ import { CodeBlock } from '@/components/code-block';
22import { EditPageLink } from '@/components/edit-page-link' ;
33import { Tabs , TabsContent , TabsList , TabsTrigger } from '@/components/ui/tabs' ;
44import { RubyCodeExample } from '@/components/ruby-code-example' ;
5- import {
6- getActionMailerDeliverLog ,
7- getActionMailerErrorLog ,
8- getActiveJobLog ,
9- getSidekiqProcessLog ,
10- getSidekiqErrorLog ,
11- getIPSpoofLog ,
12- getCSRFViolationLog ,
13- getBlockedHostLog ,
14- getGeneralExceptionLog ,
15- getHostAuthorizationLog ,
16- getLogRageLog ,
17- getShrineLog ,
18- getCarrierWaveLog ,
19- getActiveStorageLog ,
20- } from '@/lib/log-generation' ;
5+ import { LogGenerator } from '@/lib/log-generation' ;
6+ import { LogType } from '@/lib/log-generation' ;
7+
8+ // Helper to format logs as JSON strings for display
9+ function formatLog ( log : Record < string , any > ) : string {
10+ return JSON . stringify ( log , null , 2 ) ;
11+ }
12+
13+ // Create a single log generator with a fixed seed for consistent examples
14+ const logGenerator = new LogGenerator ( 12345 ) ;
2115
2216export default function IntegrationsPage ( ) {
2317 return (
@@ -51,15 +45,15 @@ export default function IntegrationsPage() {
5145 className = "mt-0 rounded-tl-none bg-neutral-100 p-4 dark:bg-neutral-900"
5246 >
5347 < CodeBlock language = "json" unwrapped = { true } >
54- { getActionMailerDeliverLog ( ) }
48+ { formatLog ( logGenerator . generateLog ( LogType . ACTIONMAILER ) ) }
5549 </ CodeBlock >
5650 </ TabsContent >
5751 < TabsContent
5852 value = "error"
5953 className = "mt-0 rounded-tl-none bg-neutral-100 p-4 dark:bg-neutral-900"
6054 >
6155 < CodeBlock language = "json" unwrapped = { true } >
62- { getActionMailerErrorLog ( ) }
56+ { formatLog ( logGenerator . generateLog ( LogType . ACTIONMAILER ) ) }
6357 </ CodeBlock >
6458 </ TabsContent >
6559 </ Tabs >
@@ -70,7 +64,7 @@ export default function IntegrationsPage() {
7064 events with detailed information about the job.
7165 </ p >
7266
73- < CodeBlock language = "json" > { getActiveJobLog ( ) } </ CodeBlock >
67+ < CodeBlock language = "json" > { formatLog ( logGenerator . generateLog ( LogType . ACTIVEJOB ) ) } </ CodeBlock >
7468
7569 < h2 className = "text-2xl font-bold mt-10 mb-4" > Sidekiq Integration</ h2 >
7670 < p className = "text-neutral-600 dark:text-neutral-400 mb-4" >
@@ -89,15 +83,15 @@ export default function IntegrationsPage() {
8983 < TabsContent value = "process" className = "mt-4" >
9084 < div className = "rounded-lg bg-neutral-100 p-4 dark:bg-neutral-900" >
9185 < CodeBlock language = "json" unwrapped = { true } >
92- { getSidekiqProcessLog ( ) }
86+ { formatLog ( logGenerator . generateLog ( LogType . SIDEKIQ ) ) }
9387 </ CodeBlock >
9488 </ div >
9589 </ TabsContent >
9690
9791 < TabsContent value = "error" className = "mt-4" >
9892 < div className = "rounded-lg bg-neutral-100 p-4 dark:bg-neutral-900" >
9993 < CodeBlock language = "json" unwrapped = { true } >
100- { getSidekiqErrorLog ( ) }
94+ { formatLog ( logGenerator . generateLog ( LogType . SIDEKIQ ) ) }
10195 </ CodeBlock >
10296 </ div >
10397 </ TabsContent >
@@ -113,7 +107,7 @@ export default function IntegrationsPage() {
113107 < RubyCodeExample name = "lograge_custom_options" />
114108
115109 < div className = "mt-4" >
116- < CodeBlock language = "json" > { getLogRageLog ( ) } </ CodeBlock >
110+ < CodeBlock language = "json" > { formatLog ( logGenerator . generateLog ( LogType . REQUEST ) ) } </ CodeBlock >
117111 </ div >
118112
119113 < h2 className = "text-2xl font-bold mt-10 mb-4" > Shrine Integration</ h2 >
@@ -122,15 +116,15 @@ export default function IntegrationsPage() {
122116 other Shrine operations, including file metadata and operation duration.
123117 </ p >
124118
125- < CodeBlock language = "json" > { getShrineLog ( ) } </ CodeBlock >
119+ < CodeBlock language = "json" > { formatLog ( logGenerator . generateLog ( LogType . SHRINE ) ) } </ CodeBlock >
126120
127121 < h2 className = "text-2xl font-bold mt-10 mb-4" > CarrierWave Integration</ h2 >
128122 < p className = "text-neutral-600 dark:text-neutral-400 mb-4" >
129123 Similar to the Shrine integration, the CarrierWave integration adds
130124 structured logging for file upload operations.
131125 </ p >
132126
133- < CodeBlock language = "json" > { getCarrierWaveLog ( ) } </ CodeBlock >
127+ < CodeBlock language = "json" > { formatLog ( logGenerator . generateLog ( LogType . CARRIERWAVE ) ) } </ CodeBlock >
134128
135129 < h2 className = "text-2xl font-bold mt-10 mb-4" >
136130 ActiveStorage Integration
@@ -141,56 +135,20 @@ export default function IntegrationsPage() {
141135 storage service.
142136 </ p >
143137
144- < CodeBlock language = "json" > { getActiveStorageLog ( ) } </ CodeBlock >
138+ < CodeBlock language = "json" > { formatLog ( logGenerator . generateLog ( LogType . ACTIVESTORAGE ) ) } </ CodeBlock >
145139
146140 < h2 className = "text-2xl font-bold mt-10 mb-4" > Rack Error Handler</ h2 >
147141 < p className = "text-neutral-600 dark:text-neutral-400 mb-4" >
148142 LogStruct includes a Rack middleware that enhances error logging for
149143 Rails applications. This middleware catches and logs security violations
150144 and other exceptions with detailed context. The rack error handler logs
151- security violations like:
145+ security violations like IP spoofing attacks, CSRF token errors, blocked
146+ host attempts, and general exceptions during request processing.
152147 </ p >
153148
154- < Tabs defaultValue = "ip-spoof" >
155- < TabsList className = "" >
156- < TabsTrigger value = "ip-spoof" > IP Spoofing</ TabsTrigger >
157- < TabsTrigger value = "csrf" > CSRF Violation</ TabsTrigger >
158- < TabsTrigger value = "blocked-host" > Blocked Host</ TabsTrigger >
159- < TabsTrigger value = "exception" > General Exception</ TabsTrigger >
160- </ TabsList >
161-
162- < TabsContent value = "ip-spoof" >
163- < div className = "rounded-lg bg-neutral-100 p-4 dark:bg-neutral-900" >
164- < CodeBlock language = "json" unwrapped = { true } >
165- { getIPSpoofLog ( ) }
166- </ CodeBlock >
167- </ div >
168- </ TabsContent >
169-
170- < TabsContent value = "csrf" >
171- < div className = "rounded-lg bg-neutral-100 p-4 dark:bg-neutral-900" >
172- < CodeBlock language = "json" unwrapped = { true } >
173- { getCSRFViolationLog ( ) }
174- </ CodeBlock >
175- </ div >
176- </ TabsContent >
177-
178- < TabsContent value = "blocked-host" >
179- < div className = "rounded-lg bg-neutral-100 p-4 dark:bg-neutral-900" >
180- < CodeBlock language = "json" unwrapped = { true } >
181- { getBlockedHostLog ( ) }
182- </ CodeBlock >
183- </ div >
184- </ TabsContent >
185-
186- < TabsContent value = "exception" >
187- < div className = "rounded-lg bg-neutral-100 p-4 dark:bg-neutral-900" >
188- < CodeBlock language = "json" unwrapped = { true } >
189- { getGeneralExceptionLog ( ) }
190- </ CodeBlock >
191- </ div >
192- </ TabsContent >
193- </ Tabs >
149+ < CodeBlock language = "json" >
150+ { formatLog ( logGenerator . generateLog ( LogType . SECURITY ) ) }
151+ </ CodeBlock >
194152
195153 < h2 className = "text-2xl font-bold mt-10 mb-4" > Host Authorization</ h2 >
196154 < p className = "text-neutral-600 dark:text-neutral-400 mb-4" >
@@ -199,7 +157,7 @@ export default function IntegrationsPage() {
199157 potential security issues.
200158 </ p >
201159
202- < CodeBlock language = "json" > { getHostAuthorizationLog ( ) } </ CodeBlock >
160+ < CodeBlock language = "json" > { formatLog ( logGenerator . generateLog ( LogType . SECURITY ) ) } </ CodeBlock >
203161
204162 < h2 className = "text-2xl font-bold mt-10 mb-4" > Sorbet Integration</ h2 >
205163 < p className = "text-neutral-600 dark:text-neutral-400 mb-4" >
@@ -209,16 +167,35 @@ export default function IntegrationsPage() {
209167 crashing your application.
210168 </ p >
211169
212- < CodeBlock language = "ruby" >
213- { `# Enable Sorbet error handling
170+ < Tabs defaultValue = "config" >
171+ < TabsList className = "mb-4" >
172+ < TabsTrigger value = "config" > Configuration</ TabsTrigger >
173+ < TabsTrigger value = "error" > Type Error Example</ TabsTrigger >
174+ </ TabsList >
175+
176+ < TabsContent value = "config" >
177+ < div className = "rounded-lg bg-neutral-100 p-4 dark:bg-neutral-900" >
178+ < CodeBlock language = "ruby" unwrapped = { true } >
179+ { `# Enable Sorbet error handling
214180config.integrations.enable_sorbet_error_handlers = true
215181
216182# This configures the following error handlers:
217183# - T::Configuration.inline_type_error_handler
218184# - T::Configuration.call_validation_error_handler
219185# - T::Configuration.sig_builder_error_handler
220186# - T::Configuration.sig_validation_error_handler` }
221- </ CodeBlock >
187+ </ CodeBlock >
188+ </ div >
189+ </ TabsContent >
190+
191+ < TabsContent value = "error" >
192+ < div className = "rounded-lg bg-neutral-100 p-4 dark:bg-neutral-900" >
193+ < CodeBlock language = "json" unwrapped = { true } >
194+ { formatLog ( logGenerator . generateLog ( LogType . ERROR ) ) }
195+ </ CodeBlock >
196+ </ div >
197+ </ TabsContent >
198+ </ Tabs >
222199
223200 < EditPageLink />
224201 </ div >
0 commit comments