From 89a0948de0e86c23e6365d787db99656f69a5f28 Mon Sep 17 00:00:00 2001 From: Matias Chomicki Date: Wed, 17 Sep 2025 17:26:16 +0200 Subject: [PATCH] LogListControls: show levels from displayed logs --- public/app/features/logs/components/panel/LogList.tsx | 6 ++++-- .../features/logs/components/panel/LogListControls.tsx | 2 +- public/app/features/logs/components/panel/processing.ts | 8 ++++++++ 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/public/app/features/logs/components/panel/LogList.tsx b/public/app/features/logs/components/panel/LogList.tsx index 0916541c4fc..0cd76458975 100644 --- a/public/app/features/logs/components/panel/LogList.tsx +++ b/public/app/features/logs/components/panel/LogList.tsx @@ -31,7 +31,7 @@ import { LogListContextProvider, LogListState, useLogListContext } from './LogLi import { LogListControls } from './LogListControls'; import { LOG_LIST_SEARCH_HEIGHT, LogListSearch } from './LogListSearch'; import { LogListSearchContextProvider, useLogListSearchContext } from './LogListSearchContext'; -import { preProcessLogs, LogListModel } from './processing'; +import { preProcessLogs, LogListModel, getLevelsFromLogs } from './processing'; import { useKeyBindings } from './useKeyBindings'; import { usePopoverMenu } from './usePopoverMenu'; import { LogLineVirtualization, getLogLineSize, LogFieldDimension, ScrollToLogsEvent } from './virtualization'; @@ -410,6 +410,8 @@ const LogListComponent = ({ [debouncedScrollToItem, filteredLogs] ); + const logLevels = useMemo(() => getLevelsFromLogs(processedLogs), [processedLogs]); + if (!containerElement || listHeight == null) { // Wait for container to be rendered return null; @@ -417,7 +419,7 @@ const LogListComponent = ({ return (
- {showControls && } + {showControls && } {detailsMode === 'sidebar' && showDetails.length > 0 && ( ), - [filterLevels, onFilterLevelClick, styles.menuItemActive] + [filterLevels, logLevels, onFilterLevelClick, styles.menuItemActive] ); const downloadMenu = useMemo( diff --git a/public/app/features/logs/components/panel/processing.ts b/public/app/features/logs/components/panel/processing.ts index dbb060a744c..4d8236a7a79 100644 --- a/public/app/features/logs/components/panel/processing.ts +++ b/public/app/features/logs/components/panel/processing.ts @@ -326,3 +326,11 @@ function countNewLines(log: string, limit = Infinity) { } return count; } + +export function getLevelsFromLogs(logs: LogListModel[]) { + const levels = new Set(); + for (const log of logs) { + levels.add(log.logLevel); + } + return Array.from(levels).filter(level => level != null); +}