Skip to content

Commit

Permalink
refactore codes
Browse files Browse the repository at this point in the history
  • Loading branch information
vishalmishraa committed Oct 18, 2024
1 parent 55f404e commit b26aa4e
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 36 deletions.
21 changes: 5 additions & 16 deletions web-server/src/components/Service/SystemLog/FormattedLog.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,9 @@ import { useTheme } from '@mui/material';
import { useCallback } from 'react';

import { Line } from '@/components/Text';
import { ParsedLog } from '@/constants/log-formatter';
import { ParsedLog } from '@/types/resources';

export const FormattedLog = ({
log,
index
}: {
log: ParsedLog;
index: number;
}) => {
export const FormattedLog = ({ log }: { log: ParsedLog; index: number }) => {
const theme = useTheme();
const getLevelColor = useCallback(
(level: string) => {
Expand Down Expand Up @@ -40,17 +34,12 @@ export const FormattedLog = ({

const { timestamp, ip, logLevel, message } = log;
return (
<Line
key={index}
marginBottom={'8px'}
fontSize={'14px'}
fontFamily={'monospace'}
>
<Line component="span" color="info.main">
<Line medium marginBottom={'8px'} fontFamily={'monospace'}>
<Line component="span" color="info">
{timestamp}
</Line>{' '}
{ip && (
<Line component="span" color="primary.main">
<Line component="span" color="primary">
{ip}{' '}
</Line>
)}
Expand Down
9 changes: 2 additions & 7 deletions web-server/src/components/Service/SystemLog/PlainLog.tsx
Original file line number Diff line number Diff line change
@@ -1,13 +1,8 @@
import { Line } from '@/components/Text';

export const PlainLog = ({ log, index }: { log: string; index: number }) => {
export const PlainLog = ({ log }: { log: string; index: number }) => {
return (
<Line
key={index}
marginBottom={'8px'}
fontSize={'14px'}
fontFamily={'monospace'}
>
<Line medium marginBottom={'8px'} fontFamily={'monospace'}>
{log}
</Line>
);
Expand Down
8 changes: 0 additions & 8 deletions web-server/src/constants/log-formatter.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,3 @@
export interface ParsedLog {
timestamp: string;
logLevel: string;
message: string;
role?: string;
ip?: string;
}

export const generalLogRegex =
/^\[(.*?)\] \[(\d+)\] \[(INFO|ERROR|WARN|DEBUG|WARNING|CRITICAL)\] (.+)$/;
export const httpLogRegex =
Expand Down
8 changes: 4 additions & 4 deletions web-server/src/hooks/useSystemLogs.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ export const useSystemLogs = ({
}) => {
const services = useSelector((state) => state.service.services);
const loading = useSelector((state) => state.service.loading);

const logs = useMemo(() => {
return services[serviceName]?.logs || [];
}, [serviceName, services]);
const logs = useMemo(
() => services[serviceName]?.logs || [],
[serviceName, services]
);

return {
services,
Expand Down
8 changes: 8 additions & 0 deletions web-server/src/types/resources.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1052,3 +1052,11 @@ export enum LogLevel {
'STATEMENT' = 'STATEMENT',
'DETAIL' = 'DETAIL'
}

export interface ParsedLog {
timestamp: string;
logLevel: string;
message: string;
role?: string;
ip?: string;
}
2 changes: 1 addition & 1 deletion web-server/src/utils/logFormatter.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { LogLevel } from '@/types/resources';
import { ParsedLog } from '@/types/resources';

import {
ParsedLog,
generalLogRegex,
httpLogRegex,
redisLogRegex,
Expand Down

0 comments on commit b26aa4e

Please sign in to comment.