diff --git a/logstable/src/components/LogRow/LogRow.tsx b/logstable/src/components/LogRow/LogRow.tsx index d64ee2c0..5253ed07 100644 --- a/logstable/src/components/LogRow/LogRow.tsx +++ b/logstable/src/components/LogRow/LogRow.tsx @@ -12,9 +12,10 @@ // limitations under the License. import React, { memo, useCallback } from 'react'; -import { Box, Collapse, useTheme } from '@mui/material'; +import { Box, Collapse } from '@mui/material'; import ChevronRight from 'mdi-material-ui/ChevronRight'; import { LogEntry } from '@perses-dev/core'; +import { useSeverityColor } from '../hooks/useSeverity'; import { LogTimestamp } from './LogTimestamp'; import { LogRowContainer, LogRowContent, ExpandButton, LogText } from './LogsStyles'; import { LogDetailsTable } from './LogDetailsTable'; @@ -38,8 +39,7 @@ const DefaultLogRow: React.FC = ({ showTime = false, allowWrap = false, }) => { - const theme = useTheme(); - const severityColor = theme.palette.text.secondary; + const severityColor = useSeverityColor(log); const handleToggle = useCallback(() => { if (isExpandable) { diff --git a/logstable/src/components/hooks/useSeverity.ts b/logstable/src/components/hooks/useSeverity.ts new file mode 100644 index 00000000..4118aad4 --- /dev/null +++ b/logstable/src/components/hooks/useSeverity.ts @@ -0,0 +1,37 @@ +// Copyright 2025 The Perses Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import { useTheme } from '@mui/material'; +import { LogEntry } from '@perses-dev/core'; +import { getSeverity } from '../utils'; + +export const useSeverityColor = (log?: LogEntry) => { + const theme = useTheme(); + if (!log) { + return theme.palette.text.secondary; + } + const severity = getSeverity(log); + + switch (severity) { + case 'error': + return theme.palette.error.main; + case 'warn': + return theme.palette.warning.main; + case 'info': + return theme.palette.info.main; + case 'debug': + return theme.palette.primary.main; + default: + return theme.palette.text.secondary; + } +}; diff --git a/logstable/src/components/utils.ts b/logstable/src/components/utils.ts new file mode 100644 index 00000000..4ee39185 --- /dev/null +++ b/logstable/src/components/utils.ts @@ -0,0 +1,29 @@ +// Copyright 2025 The Perses Authors +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +import { LogEntry } from '@perses-dev/core'; + +export const getSeverity = (log: LogEntry): 'info' | 'warn' | 'error' | 'debug' | 'unknown' => { + const level = log.labels?.level?.toLowerCase(); + + if (level) { + if (level.includes('critical')) return 'error'; + if (level.includes('fatal')) return 'error'; + if (level.includes('error') || level.includes('err')) return 'error'; + if (level.includes('warn')) return 'warn'; + if (level.includes('info')) return 'info'; + if (level.includes('debug')) return 'debug'; + } + + return 'unknown'; +};