Skip to content

Commit 6f648ea

Browse files
committed
updated puma log on homepage
1 parent a7acf47 commit 6f648ea

1 file changed

Lines changed: 17 additions & 21 deletions

File tree

site/components/log-scroller.tsx

Lines changed: 17 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,11 @@ import { Prism as SyntaxHighlighter } from 'react-syntax-highlighter';
55
import { atomDark } from 'react-syntax-highlighter/dist/esm/styles/prism';
66
import useInterval from 'use-interval';
77
import { LogGenerator } from '../lib/log-generation/log-generator';
8-
import { LogType } from '@/generated/logstruct';
8+
import { Event, LogType } from '@/generated/logstruct';
99

1010
// For generating random logs
1111
const logGenerator = new LogGenerator();
1212

13-
// Puma boot log template - will always be the first log
14-
const pumaLogTemplate = { src: 'puma', evt: 'boot', pid: 0, lvl: 'info' };
15-
1613
export function LogScroller() {
1714
const [logs, setLogs] = useState<string[]>([]);
1815
const [isPaused, setIsPaused] = useState(false);
@@ -58,37 +55,36 @@ export function LogScroller() {
5855
return jsonStr;
5956
}, []);
6057

61-
// Generate the Puma boot log entry (always first)
62-
const generatePumaBootLogEntry = useCallback(() => {
63-
// Use the puma boot template
64-
const log = JSON.parse(JSON.stringify(pumaLogTemplate));
65-
66-
// Add current timestamp
67-
log.ts = new Date().toISOString();
68-
69-
// Add pid
70-
log.pid = Math.floor(Math.random() * 60000) + 1000;
58+
// Generate the Puma start log entry (always first)
59+
const generatePumaStartLogEntry = useCallback(() => {
60+
const log = logGenerator.generateLogWithOptions(LogType.PUMA, {
61+
preferredEvent: Event.Start,
62+
});
7163

7264
return formatLogForDisplay(log);
7365
}, [formatLogForDisplay]);
7466

7567
// Generate a random log entry (for logs after the Puma boot)
7668
const generateLogEntry = useCallback(() => {
77-
// Pick a random log type
78-
const logTypes = Object.values(LogType);
79-
const randomLogType = logTypes[Math.floor(Math.random() * logTypes.length)];
69+
// Pick a random log type, excluding Puma once the initial start log is shown
70+
const logTypes = Object.values(LogType).filter(
71+
(type) => type !== LogType.PUMA,
72+
);
73+
const randomLogType = logTypes[
74+
Math.floor(Math.random() * logTypes.length)
75+
] as LogType;
8076

8177
// Generate a random log using the LogGenerator
8278
const log = logGenerator.generateLog(randomLogType);
8379

8480
return formatLogForDisplay(log);
8581
}, [formatLogForDisplay]);
8682

87-
// Initialize with the Puma boot log
83+
// Initialize with the Puma start log
8884
useEffect(() => {
89-
// Start with only the Puma boot log
90-
setLogs([generatePumaBootLogEntry()]);
91-
}, [generatePumaBootLogEntry]);
85+
// Start with only the Puma start log
86+
setLogs([generatePumaStartLogEntry()]);
87+
}, [generatePumaStartLogEntry]);
9288

9389
// Add a new log entry at an interval, but not when user is hovering (isPaused) unless maximized
9490
useInterval(() => {

0 commit comments

Comments
 (0)