Merge pull request #1974 from Stijnus/BOLTDIY_LOGGING_DEBUGGING_FEAT

feat: comprehensive debug logging system with capture and download
This commit is contained in:
Stijnus
2025-09-07 10:42:57 +02:00
committed by GitHub
7 changed files with 1495 additions and 12 deletions

View File

@@ -130,6 +130,29 @@ export const AvatarDropdown = ({ onSelectTab }: AvatarDropdownProps) => {
Report Bug Report Bug
</DropdownMenu.Item> </DropdownMenu.Item>
<DropdownMenu.Item
className={classNames(
'flex items-center gap-2 px-4 py-2.5',
'text-sm text-gray-700 dark:text-gray-200',
'hover:bg-purple-50 dark:hover:bg-purple-500/10',
'hover:text-purple-500 dark:hover:text-purple-400',
'cursor-pointer transition-all duration-200',
'outline-none',
'group',
)}
onClick={async () => {
try {
const { downloadDebugLog } = await import('~/utils/debugLogger');
await downloadDebugLog();
} catch (error) {
console.error('Failed to download debug log:', error);
}
}}
>
<div className="i-ph:download w-4 h-4 text-gray-400 group-hover:text-purple-500 dark:group-hover:text-purple-400 transition-colors" />
Download Debug Log
</DropdownMenu.Item>
<DropdownMenu.Item <DropdownMenu.Item
className={classNames( className={classNames(
'flex items-center gap-2 px-4 py-2.5', 'flex items-center gap-2 px-4 py-2.5',

View File

@@ -19,19 +19,35 @@ export function HeaderActionButtons({ chatStarted: _chatStarted }: HeaderActionB
{/* Deploy Button */} {/* Deploy Button */}
{shouldShowButtons && <DeployButton />} {shouldShowButtons && <DeployButton />}
{/* Bug Report Button */} {/* Debug Tools */}
{shouldShowButtons && ( {shouldShowButtons && (
<div className="flex border border-bolt-elements-borderColor rounded-md overflow-hidden text-sm"> <div className="flex border border-bolt-elements-borderColor rounded-md overflow-hidden text-sm">
<button <button
onClick={() => onClick={() =>
window.open('https://github.com/stackblitz-labs/bolt.diy/issues/new?template=bug_report.yml', '_blank') window.open('https://github.com/stackblitz-labs/bolt.diy/issues/new?template=bug_report.yml', '_blank')
} }
className="rounded-md items-center justify-center [&:is(:disabled,.disabled)]:cursor-not-allowed [&:is(:disabled,.disabled)]:opacity-60 px-3 py-1.5 text-xs bg-accent-500 text-white hover:text-bolt-elements-item-contentAccent [&:not(:disabled,.disabled)]:hover:bg-bolt-elements-button-primary-backgroundHover outline-accent-500 flex gap-1.5" className="rounded-l-md items-center justify-center [&:is(:disabled,.disabled)]:cursor-not-allowed [&:is(:disabled,.disabled)]:opacity-60 px-3 py-1.5 text-xs bg-accent-500 text-white hover:text-bolt-elements-item-contentAccent [&:not(:disabled,.disabled)]:hover:bg-bolt-elements-button-primary-backgroundHover outline-accent-500 flex gap-1.5"
title="Report Bug" title="Report Bug"
> >
<div className="i-ph:bug" /> <div className="i-ph:bug" />
<span>Report Bug</span> <span>Report Bug</span>
</button> </button>
<div className="w-px bg-bolt-elements-borderColor" />
<button
onClick={async () => {
try {
const { downloadDebugLog } = await import('~/utils/debugLogger');
await downloadDebugLog();
} catch (error) {
console.error('Failed to download debug log:', error);
}
}}
className="rounded-r-md items-center justify-center [&:is(:disabled,.disabled)]:cursor-not-allowed [&:is(:disabled,.disabled)]:opacity-60 px-3 py-1.5 text-xs bg-accent-500 text-white hover:text-bolt-elements-item-contentAccent [&:not(:disabled,.disabled)]:hover:bg-bolt-elements-button-primary-backgroundHover outline-accent-500 flex gap-1.5"
title="Download Debug Log"
>
<div className="i-ph:download" />
<span>Debug Log</span>
</button>
</div> </div>
)} )}
</div> </div>

View File

@@ -93,6 +93,24 @@ export default function App() {
userAgent: navigator.userAgent, userAgent: navigator.userAgent,
timestamp: new Date().toISOString(), timestamp: new Date().toISOString(),
}); });
// Initialize debug logging with improved error handling
import('./utils/debugLogger')
.then(({ debugLogger }) => {
/*
* The debug logger initializes itself and starts disabled by default
* It will only start capturing when enableDebugMode() is called
*/
const status = debugLogger.getStatus();
logStore.logSystem('Debug logging ready', {
initialized: status.initialized,
capturing: status.capturing,
enabled: status.enabled,
});
})
.catch((error) => {
logStore.logError('Failed to initialize debug logging', error);
});
}, []); }, []);
return ( return (

View File

@@ -0,0 +1,69 @@
import { json } from '@remix-run/cloudflare';
import { execSync } from 'child_process';
import { existsSync } from 'fs';
export async function loader() {
try {
// Check if we're in a git repository
if (!existsSync('.git')) {
return json({
branch: 'unknown',
commit: 'unknown',
isDirty: false,
});
}
// Get current branch
const branch = execSync('git rev-parse --abbrev-ref HEAD', { encoding: 'utf8' }).trim();
// Get current commit hash
const commit = execSync('git rev-parse HEAD', { encoding: 'utf8' }).trim();
// Check if working directory is dirty
const statusOutput = execSync('git status --porcelain', { encoding: 'utf8' });
const isDirty = statusOutput.trim().length > 0;
// Get remote URL
let remoteUrl: string | undefined;
try {
remoteUrl = execSync('git remote get-url origin', { encoding: 'utf8' }).trim();
} catch {
// No remote origin, leave as undefined
}
// Get last commit info
let lastCommit: { message: string; date: string; author: string } | undefined;
try {
const commitInfo = execSync('git log -1 --pretty=format:"%s|%ci|%an"', { encoding: 'utf8' }).trim();
const [message, date, author] = commitInfo.split('|');
lastCommit = {
message: message || 'unknown',
date: date || 'unknown',
author: author || 'unknown',
};
} catch {
// Could not get commit info
}
return json({
branch,
commit,
isDirty,
remoteUrl,
lastCommit,
});
} catch (error) {
console.error('Error fetching git info:', error);
return json(
{
branch: 'error',
commit: 'error',
isDirty: false,
error: error instanceof Error ? error.message : 'Unknown error',
},
{ status: 500 },
);
}
}

1284
app/utils/debugLogger.ts Normal file

File diff suppressed because it is too large Load Diff

View File

@@ -17,21 +17,21 @@ interface Logger {
let currentLevel: DebugLevel = import.meta.env.VITE_LOG_LEVEL || (import.meta.env.DEV ? 'debug' : 'info'); let currentLevel: DebugLevel = import.meta.env.VITE_LOG_LEVEL || (import.meta.env.DEV ? 'debug' : 'info');
export const logger: Logger = { export const logger: Logger = {
trace: (...messages: any[]) => log('trace', undefined, messages), trace: (...messages: any[]) => logWithDebugCapture('trace', undefined, messages),
debug: (...messages: any[]) => log('debug', undefined, messages), debug: (...messages: any[]) => logWithDebugCapture('debug', undefined, messages),
info: (...messages: any[]) => log('info', undefined, messages), info: (...messages: any[]) => logWithDebugCapture('info', undefined, messages),
warn: (...messages: any[]) => log('warn', undefined, messages), warn: (...messages: any[]) => logWithDebugCapture('warn', undefined, messages),
error: (...messages: any[]) => log('error', undefined, messages), error: (...messages: any[]) => logWithDebugCapture('error', undefined, messages),
setLevel, setLevel,
}; };
export function createScopedLogger(scope: string): Logger { export function createScopedLogger(scope: string): Logger {
return { return {
trace: (...messages: any[]) => log('trace', scope, messages), trace: (...messages: any[]) => logWithDebugCapture('trace', scope, messages),
debug: (...messages: any[]) => log('debug', scope, messages), debug: (...messages: any[]) => logWithDebugCapture('debug', scope, messages),
info: (...messages: any[]) => log('info', scope, messages), info: (...messages: any[]) => logWithDebugCapture('info', scope, messages),
warn: (...messages: any[]) => log('warn', scope, messages), warn: (...messages: any[]) => logWithDebugCapture('warn', scope, messages),
error: (...messages: any[]) => log('error', scope, messages), error: (...messages: any[]) => logWithDebugCapture('error', scope, messages),
setLevel, setLevel,
}; };
} }
@@ -123,3 +123,40 @@ function getColorForLevel(level: DebugLevel): string {
} }
export const renderLogger = createScopedLogger('Render'); export const renderLogger = createScopedLogger('Render');
// Debug logging integration
let debugLogger: any = null;
// Lazy load debug logger to avoid circular dependencies
const getDebugLogger = () => {
if (!debugLogger && typeof window !== 'undefined') {
try {
// Use dynamic import asynchronously but don't block the function
import('./debugLogger')
.then(({ debugLogger: loggerInstance }) => {
debugLogger = loggerInstance;
})
.catch(() => {
// Debug logger not available, skip integration
});
} catch {
// Debug logger not available, skip integration
}
}
return debugLogger;
};
// Override the log function to also capture to debug logger
function logWithDebugCapture(level: DebugLevel, scope: string | undefined, messages: any[]) {
// Call original log function (the one that does the actual console logging)
log(level, scope, messages);
// Also capture to debug logger if available
const debug = getDebugLogger();
if (debug) {
debug.captureLog(level, scope, messages);
}
}

View File

@@ -36,6 +36,24 @@ export async function newShellProcess(webcontainer: WebContainer, terminal: ITer
} }
terminal.write(data); terminal.write(data);
// Capture terminal output for debugging
try {
import('~/utils/debugLogger')
.then(({ captureTerminalLog }) => {
// Clean the data by removing ANSI escape sequences for logging
const cleanData = data.replace(/\x1b\[[0-9;]*[mG]/g, '').trim();
if (cleanData) {
captureTerminalLog(cleanData, 'output');
}
})
.catch(() => {
// Ignore if debug logger is not available
});
} catch {
// Ignore errors in debug logging
}
}, },
}), }),
); );
@@ -45,6 +63,24 @@ export async function newShellProcess(webcontainer: WebContainer, terminal: ITer
if (isInteractive) { if (isInteractive) {
input.write(data); input.write(data);
// Capture terminal input for debugging
try {
import('~/utils/debugLogger')
.then(({ captureTerminalLog }) => {
// Clean the data and check if it's a command (not just cursor movement)
const cleanData = data.replace(/\x1b\[[0-9;]*[A-Z]/g, '').trim();
if (cleanData && cleanData !== '\r' && cleanData !== '\n') {
captureTerminalLog(cleanData, 'input');
}
})
.catch(() => {
// Ignore if debug logger is not available
});
} catch {
// Ignore errors in debug logging
}
} }
}); });