import React, { useState } from 'react'; import ContextList from '../context/ContextList'; import { LogLevel } from '../../types'; import CodeSnippet from '../ui/CodeSnippet'; import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'; import { faCode, faDatabase, faListUl, faStopwatch } from '@fortawesome/free-solid-svg-icons'; import { jsonStringify } from '../../util'; import Tag from 'components/ui/Tag'; import SmallButton from 'components/ui/SmallButton'; type Props = { children: React.ReactNode; context?: Record | null; time: Date; level?: LogLevel | null; meta?: Record | null; }; export default function DebugItem({ children, context = null, level = null, meta = null, time }: Props) { const [showRawContext, setShowRawContext] = useState(false); // TODO: Implement this const logLevelColors = { error: 'red', warn: 'orange', warning: 'orange', info: 'blue', debug: 'green', trace: 'gray', notice: 'purple', critical: 'red', alert: 'red', emergency: 'red', } as Record; return (
{time.toLocaleTimeString()} {level && {level}} {meta && Object.entries(meta).map(([key, value]) => ( {key === 'runtime' && ( {' '} {value} )} {key === 'connection' && ( {' '} {value} )} {key !== 'runtime' && key !== 'connection' && ( {key}: {value} )} ))} {context && ( <>
setShowRawContext(!showRawContext)}> {showRawContext ? 'As list' : 'Raw'}
)}
{children}
{context && ( <> {showRawContext ? ( ) : (
)} )}
); }