From b26aa4efa7a682880c18bff33ca9495809d73c6a Mon Sep 17 00:00:00 2001 From: vishalmishraa Date: Fri, 18 Oct 2024 12:10:41 +0530 Subject: [PATCH] refactore codes --- .../Service/SystemLog/FormattedLog.tsx | 21 +++++-------------- .../components/Service/SystemLog/PlainLog.tsx | 9 ++------ web-server/src/constants/log-formatter.ts | 8 ------- web-server/src/hooks/useSystemLogs.tsx | 8 +++---- web-server/src/types/resources.ts | 8 +++++++ web-server/src/utils/logFormatter.ts | 2 +- 6 files changed, 20 insertions(+), 36 deletions(-) diff --git a/web-server/src/components/Service/SystemLog/FormattedLog.tsx b/web-server/src/components/Service/SystemLog/FormattedLog.tsx index d85ec920..fe1c970a 100644 --- a/web-server/src/components/Service/SystemLog/FormattedLog.tsx +++ b/web-server/src/components/Service/SystemLog/FormattedLog.tsx @@ -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) => { @@ -40,17 +34,12 @@ export const FormattedLog = ({ const { timestamp, ip, logLevel, message } = log; return ( - - + + {timestamp} {' '} {ip && ( - + {ip}{' '} )} diff --git a/web-server/src/components/Service/SystemLog/PlainLog.tsx b/web-server/src/components/Service/SystemLog/PlainLog.tsx index ac96d36c..484cb6c7 100644 --- a/web-server/src/components/Service/SystemLog/PlainLog.tsx +++ b/web-server/src/components/Service/SystemLog/PlainLog.tsx @@ -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 ( - + {log} ); diff --git a/web-server/src/constants/log-formatter.ts b/web-server/src/constants/log-formatter.ts index 6039a371..352ce5a2 100644 --- a/web-server/src/constants/log-formatter.ts +++ b/web-server/src/constants/log-formatter.ts @@ -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 = diff --git a/web-server/src/hooks/useSystemLogs.tsx b/web-server/src/hooks/useSystemLogs.tsx index b795e97d..5996fa18 100644 --- a/web-server/src/hooks/useSystemLogs.tsx +++ b/web-server/src/hooks/useSystemLogs.tsx @@ -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, diff --git a/web-server/src/types/resources.ts b/web-server/src/types/resources.ts index 56c90512..6d56d2d0 100644 --- a/web-server/src/types/resources.ts +++ b/web-server/src/types/resources.ts @@ -1052,3 +1052,11 @@ export enum LogLevel { 'STATEMENT' = 'STATEMENT', 'DETAIL' = 'DETAIL' } + +export interface ParsedLog { + timestamp: string; + logLevel: string; + message: string; + role?: string; + ip?: string; +} diff --git a/web-server/src/utils/logFormatter.ts b/web-server/src/utils/logFormatter.ts index 06aa553f..40774b8e 100644 --- a/web-server/src/utils/logFormatter.ts +++ b/web-server/src/utils/logFormatter.ts @@ -1,7 +1,7 @@ import { LogLevel } from '@/types/resources'; +import { ParsedLog } from '@/types/resources'; import { - ParsedLog, generalLogRegex, httpLogRegex, redisLogRegex,