feat: Patch console.debug and display only in debug mode
- Patches `console.debug` in `ConsolePatcher.tsx` to capture debug messages. - Updates `ConsoleOutput` to only display debug messages when `debugMode` is enabled. - Passes `debugMode` prop from `App.tsx` to `ConsoleOutput`. Fixes https://github.com/google-gemini/gemini-cli/issues/397
This commit is contained in:
parent
e0b88dc8da
commit
e486d84d6a
|
@ -409,7 +409,7 @@ export const App = ({
|
||||||
cliVersion={cliVersion}
|
cliVersion={cliVersion}
|
||||||
geminiMdFileCount={geminiMdFileCount}
|
geminiMdFileCount={geminiMdFileCount}
|
||||||
/>
|
/>
|
||||||
<ConsoleOutput />
|
<ConsoleOutput debugMode={config.getDebugMode()} />
|
||||||
</Box>
|
</Box>
|
||||||
</Box>
|
</Box>
|
||||||
);
|
);
|
||||||
|
|
|
@ -10,7 +10,7 @@ import util from 'util';
|
||||||
|
|
||||||
interface ConsoleMessage {
|
interface ConsoleMessage {
|
||||||
id: Key;
|
id: Key;
|
||||||
type: 'log' | 'warn' | 'error';
|
type: 'log' | 'warn' | 'error' | 'debug';
|
||||||
content: string;
|
content: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,16 +18,24 @@ interface ConsoleMessage {
|
||||||
// This ensures IDs are unique across messages.
|
// This ensures IDs are unique across messages.
|
||||||
let messageIdCounter = 0;
|
let messageIdCounter = 0;
|
||||||
|
|
||||||
export const ConsoleOutput: React.FC = () => {
|
interface ConsoleOutputProps {
|
||||||
|
debugMode: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export const ConsoleOutput: React.FC<ConsoleOutputProps> = ({ debugMode }) => {
|
||||||
const [messages, setMessages] = useState<ConsoleMessage[]>([]);
|
const [messages, setMessages] = useState<ConsoleMessage[]>([]);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const originalConsoleLog = console.log;
|
const originalConsoleLog = console.log;
|
||||||
const originalConsoleWarn = console.warn;
|
const originalConsoleWarn = console.warn;
|
||||||
const originalConsoleError = console.error;
|
const originalConsoleError = console.error;
|
||||||
|
const originalConsoleDebug = console.debug;
|
||||||
|
|
||||||
const formatArgs = (args: unknown[]): string => util.format(...args);
|
const formatArgs = (args: unknown[]): string => util.format(...args);
|
||||||
const addMessage = (type: 'log' | 'warn' | 'error', args: unknown[]) => {
|
const addMessage = (
|
||||||
|
type: 'log' | 'warn' | 'error' | 'debug',
|
||||||
|
args: unknown[],
|
||||||
|
) => {
|
||||||
setMessages((prevMessages) => [
|
setMessages((prevMessages) => [
|
||||||
...prevMessages,
|
...prevMessages,
|
||||||
{
|
{
|
||||||
|
@ -42,17 +50,23 @@ export const ConsoleOutput: React.FC = () => {
|
||||||
console.log = (...args: unknown[]) => addMessage('log', args);
|
console.log = (...args: unknown[]) => addMessage('log', args);
|
||||||
console.warn = (...args: unknown[]) => addMessage('warn', args);
|
console.warn = (...args: unknown[]) => addMessage('warn', args);
|
||||||
console.error = (...args: unknown[]) => addMessage('error', args);
|
console.error = (...args: unknown[]) => addMessage('error', args);
|
||||||
|
console.debug = (...args: unknown[]) => addMessage('debug', args);
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
console.log = originalConsoleLog;
|
console.log = originalConsoleLog;
|
||||||
console.warn = originalConsoleWarn;
|
console.warn = originalConsoleWarn;
|
||||||
console.error = originalConsoleError;
|
console.error = originalConsoleError;
|
||||||
|
console.debug = originalConsoleDebug;
|
||||||
};
|
};
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Box flexDirection="column">
|
<Box flexDirection="column">
|
||||||
{messages.map((msg) => {
|
{messages.map((msg) => {
|
||||||
|
if (msg.type === 'debug' && !debugMode) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
const textProps: { color?: string } = {};
|
const textProps: { color?: string } = {};
|
||||||
let prefix = '';
|
let prefix = '';
|
||||||
|
|
||||||
|
@ -65,6 +79,10 @@ export const ConsoleOutput: React.FC = () => {
|
||||||
textProps.color = 'red';
|
textProps.color = 'red';
|
||||||
prefix = 'ERROR: ';
|
prefix = 'ERROR: ';
|
||||||
break;
|
break;
|
||||||
|
case 'debug':
|
||||||
|
textProps.color = 'gray';
|
||||||
|
prefix = 'DEBUG: ';
|
||||||
|
break;
|
||||||
case 'log':
|
case 'log':
|
||||||
default:
|
default:
|
||||||
prefix = 'LOG: ';
|
prefix = 'LOG: ';
|
||||||
|
|
Loading…
Reference in New Issue