Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加Debug级别日志捕获,同时也支持了日志级别的筛选 #102

Merged
merged 3 commits into from
Dec 26, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/assets/image/debug.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
36 changes: 30 additions & 6 deletions src/pages/Devtools/ConsolePanel/components/HeaderActions/index.tsx
Original file line number Diff line number Diff line change
@@ -1,24 +1,48 @@
import { useSocketMessageStore } from '@/store/socket-message';
import { ClearOutlined } from '@ant-design/icons';
import { Row, Col, Tooltip, Button } from 'antd';
import { Row, Col, Tooltip, Button, Select, Space } from 'antd';
import { useCallback } from 'react';
import { useTranslation } from 'react-i18next';

export const HeaderActions = () => {
const { t } = useTranslation();
const clearRecord = useSocketMessageStore((state) => state.clearRecord);
const changeConsoleMsgFilter = useSocketMessageStore(
(state) => state.setConsoleMsgTypeFilter,
);

const logLevelList = [
{ label: 'Debug', value: 'debug' },
{ label: 'Info', value: 'info' },
{
label: 'Warnings',
value: 'warn',
},
{ label: 'Errors', value: 'error' },
{ label: 'Log', value: 'log' },
];

const clear = useCallback(() => {
clearRecord('console');
}, [clearRecord]);
return (
<Row justify="end">
<Col>
<Tooltip title={t('common.clear')}>
<Button onClick={clear}>
<ClearOutlined />
</Button>
</Tooltip>
<Space>
<Select
onChange={changeConsoleMsgFilter}
maxTagCount="responsive"
mode="multiple"
options={logLevelList}
placeholder="Log Level Filter"
style={{ width: 200 }}
/>
<Tooltip title={t('common.clear')}>
<Button onClick={clear}>
<ClearOutlined />
</Button>
</Tooltip>
</Space>
</Col>
</Row>
);
Expand Down
6 changes: 6 additions & 0 deletions src/pages/Devtools/ConsolePanel/components/LogType/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ import { ReactComponent as WarnSvg } from '@/assets/image/warn.svg';
import { ReactComponent as DebugOriginSvg } from '@/assets/image/debug-origin.svg';
import { ReactComponent as DebugEvalSvg } from '@/assets/image/debug-eval.svg';
import { ReactComponent as UserSvg } from '@/assets/image/user.svg';
import { ReactComponent as DebugSvg } from '@/assets/image/debug.svg';
import './index.less';
import type { SpyConsole } from '@huolala-tech/page-spy';

interface ThemeItem {
color: string;
icon: React.ComponentType | null;
}

type Theme = Record<SpyConsole.DataType | 'default', ThemeItem>;

const Type2Theme: Partial<Theme> = {
Expand All @@ -28,6 +30,10 @@ const Type2Theme: Partial<Theme> = {
color: '#E9994B',
icon: WarnSvg,
},
debug: {
color: '#8236CB',
icon: DebugSvg,
},
'debug-origin': {
color: '#8236CB',
icon: DebugOriginSvg,
Expand Down
61 changes: 34 additions & 27 deletions src/pages/Devtools/ConsolePanel/components/MainContent/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ export const MainContent = () => {
}, []);

const [data] = useSocketMessageStore((state) => [state.consoleMsg]);
const [dataFilter] = useSocketMessageStore((state) => [
state.consoleMsgTypeFilter,
]);
const [newTips, setNewTips] = useState<boolean>(false);
useEffect(() => {
if (data.length === 0) {
Expand Down Expand Up @@ -72,34 +75,38 @@ export const MainContent = () => {

return (
<div className="console-list" ref={containerEl}>
{data.map((item) => (
<div className={`console-item ${item.logType}`} key={item.id}>
<div className="console-item__title">
<LogType type={item.logType} />
{data
.filter((item) =>
dataFilter.length ? dataFilter.includes(item.logType) : item,
)
.map((item) => (
<div className={`console-item ${item.logType}`} key={item.id}>
<div className="console-item__title">
<LogType type={item.logType} />
</div>
<div className="console-item__content">
<Row gutter={12} wrap={false}>
<Col style={{ flexShrink: 0 }}>
<Timestamp time={item.time} />
</Col>
<Col flex={1}>
{isPlaceholderNode(item) ? (
<PlaceholderNode data={item.logs} />
) : isErrorTraceNode(item) ? (
<ErrorTraceNode data={item} />
) : (
item.logs?.map((log) => {
return <ConsoleNode data={log} key={log.id} />;
})
)}
</Col>
</Row>
</div>
<div className="console-item__url" title={item.url}>
{item.url?.substring(new URL(item.url).origin.length)}
</div>
</div>
<div className="console-item__content">
<Row gutter={12} wrap={false}>
<Col style={{ flexShrink: 0 }}>
<Timestamp time={item.time} />
</Col>
<Col flex={1}>
{isPlaceholderNode(item) ? (
<PlaceholderNode data={item.logs} />
) : isErrorTraceNode(item) ? (
<ErrorTraceNode data={item} />
) : (
item.logs?.map((log) => {
return <ConsoleNode data={log} key={log.id} />;
})
)}
</Col>
</Row>
</div>
<div className="console-item__url" title={item.url}>
{item.url?.substring(new URL(item.url).origin.length)}
</div>
</div>
))}
))}
{newTips && (
<div className="console-list__new" onClick={scrollToBottom}>
<Button shape="round" type="primary">
Expand Down
3 changes: 3 additions & 0 deletions src/pages/Devtools/ConsolePanel/index.less
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@
&:last-child {
border-bottom: 1px solid #f0f0f0;
}
&.debug {
color: #1c419a;
}
&.warn {
color: #573c10;
background-color: #fefae3;
Expand Down
6 changes: 6 additions & 0 deletions src/store/socket-message/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const USER_ID = 'Debugger';
interface SocketMessage {
socket: SocketStore | null;
consoleMsg: SpyConsole.DataItem[];
consoleMsgTypeFilter: string[];
networkMsg: SpyNetwork.RequestInfo[];
systemMsg: SpySystem.DataItem[];
connectMsg: string[];
Expand All @@ -36,13 +37,15 @@ interface SocketMessage {
data: SpyDatabase.GetTypeDataItem | null;
};
initSocket: (url: string) => void;
setConsoleMsgTypeFilter: (typeList: string[]) => void;
clearRecord: (key: string) => void;
refresh: (key: string) => void;
}

export const useSocketMessageStore = create<SocketMessage>((set, get) => ({
socket: null,
consoleMsg: [],
consoleMsgTypeFilter: [],
networkMsg: [],
systemMsg: [],
connectMsg: [],
Expand Down Expand Up @@ -243,6 +246,9 @@ export const useSocketMessageStore = create<SocketMessage>((set, get) => ({
}
});
},
setConsoleMsgTypeFilter: (typeList: string[]) => {
set({ consoleMsgTypeFilter: typeList });
},
clearRecord: (key: string) => {
switch (key) {
case 'console':
Expand Down