Files
portainer/app/docker/views/containers/logs/containerLogsController.js
agent_coder 7f02d20e54 feat(logs): React log viewer for container logs
Replace the legacy AngularJS <log-viewer> on the container logs page with a
modern React log viewer, reusing the existing streaming (#6) and formatting/
coloring pipeline. Features: line-number gutter, zerolog level + key=value
coloring (from the existing formatter spans), from/to datetime range, Lines
limit, Line numbers / Timestamp / Wrap lines toggles, Auto refresh (live tail
on/off), Search + 'Filter search results', Copy, Download logs, and fullscreen.

The viewer is source-agnostic (StreamLogsFn), so service/task logs can adopt it
later; this PR wires container logs only. containerLogsController.js no longer
opens its own live stream (React owns fetching now), preventing a double stream.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2026-07-01 19:05:56 +03:00

37 lines
1.8 KiB
JavaScript

import { trimContainerName } from '@/docker/filters/utils';
import { getContainerSubTabBreadcrumbs } from '@/react/docker/containers/ItemView/containerBreadcrumbs';
// The container logs page is now rendered entirely by the React
// <container-log-view> (see containerlogs.html), which owns fetching, live
// tailing, formatting and colouring. This controller only provides the page
// breadcrumbs and sets the agent-target header for the node the container lives
// on, so the React log stream resolves the correct node on Agent/Edge
// environments.
angular.module('portainer.docker').controller('ContainerLogsController', [
'$scope',
'$transition$',
'ContainerService',
'Notifications',
'HttpRequestHelper',
'endpoint',
function ($scope, $transition$, ContainerService, Notifications, HttpRequestHelper, endpoint) {
function initView() {
HttpRequestHelper.setPortainerAgentTargetHeader($transition$.params().nodeName);
// Set the trail up-front (without the container name) so it survives the
// load window and a load error; the success path fills in the name.
$scope.breadcrumbs = getContainerSubTabBreadcrumbs($transition$.to().name, $transition$.params(), '', 'Logs');
ContainerService.container(endpoint.Id, $transition$.params().id)
.then(function success(container) {
// Stack-aware breadcrumb: keeps the stack trail when the container was
// opened from a stack, falls back to the global Containers trail otherwise.
$scope.breadcrumbs = getContainerSubTabBreadcrumbs($transition$.to().name, $transition$.params(), trimContainerName(container.Name), 'Logs');
})
.catch(function error(err) {
Notifications.error('Failure', err, 'Unable to retrieve container information');
});
}
initView();
},
]);