2019-03-21 05:46:49 +00:00
|
|
|
import moment from 'moment';
|
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
angular.module('portainer.docker').controller('ContainerLogsController', [
|
|
|
|
'$scope',
|
|
|
|
'$transition$',
|
|
|
|
'$interval',
|
|
|
|
'ContainerService',
|
|
|
|
'Notifications',
|
|
|
|
'HttpRequestHelper',
|
|
|
|
function ($scope, $transition$, $interval, ContainerService, Notifications, HttpRequestHelper) {
|
|
|
|
$scope.state = {
|
|
|
|
refreshRate: 3,
|
|
|
|
lineCount: 100,
|
|
|
|
sinceTimestamp: '',
|
|
|
|
displayTimestamps: false,
|
|
|
|
};
|
2018-02-28 06:19:28 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
$scope.changeLogCollection = function (logCollectionStatus) {
|
|
|
|
if (!logCollectionStatus) {
|
|
|
|
stopRepeater();
|
|
|
|
} else {
|
|
|
|
setUpdateRepeater(!$scope.container.Config.Tty);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.$on('$destroy', function () {
|
2018-02-28 06:19:28 +00:00
|
|
|
stopRepeater();
|
2020-04-10 21:54:53 +00:00
|
|
|
});
|
2014-12-15 22:26:10 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
function stopRepeater() {
|
|
|
|
var repeater = $scope.repeater;
|
|
|
|
if (angular.isDefined(repeater)) {
|
|
|
|
$interval.cancel(repeater);
|
|
|
|
repeater = null;
|
|
|
|
}
|
|
|
|
}
|
2014-12-15 22:26:10 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
function setUpdateRepeater(skipHeaders) {
|
|
|
|
var refreshRate = $scope.state.refreshRate;
|
|
|
|
$scope.repeater = $interval(function () {
|
|
|
|
ContainerService.logs(
|
|
|
|
$transition$.params().id,
|
|
|
|
1,
|
|
|
|
1,
|
|
|
|
$scope.state.displayTimestamps ? 1 : 0,
|
|
|
|
moment($scope.state.sinceTimestamp).unix(),
|
|
|
|
$scope.state.lineCount,
|
|
|
|
skipHeaders
|
|
|
|
)
|
|
|
|
.then(function success(data) {
|
|
|
|
$scope.logs = data;
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
stopRepeater();
|
|
|
|
Notifications.error('Failure', err, 'Unable to retrieve container logs');
|
|
|
|
});
|
|
|
|
}, refreshRate * 1000);
|
2018-02-28 06:19:28 +00:00
|
|
|
}
|
2015-02-21 18:09:12 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
function startLogPolling(skipHeaders) {
|
2018-10-29 04:49:35 +00:00
|
|
|
ContainerService.logs($transition$.params().id, 1, 1, $scope.state.displayTimestamps ? 1 : 0, moment($scope.state.sinceTimestamp).unix(), $scope.state.lineCount, skipHeaders)
|
2020-04-10 21:54:53 +00:00
|
|
|
.then(function success(data) {
|
|
|
|
$scope.logs = data;
|
|
|
|
setUpdateRepeater(skipHeaders);
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
stopRepeater();
|
|
|
|
Notifications.error('Failure', err, 'Unable to retrieve container logs');
|
|
|
|
});
|
|
|
|
}
|
2014-12-15 22:26:10 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
function initView() {
|
|
|
|
HttpRequestHelper.setPortainerAgentTargetHeader($transition$.params().nodeName);
|
|
|
|
ContainerService.container($transition$.params().id)
|
|
|
|
.then(function success(data) {
|
|
|
|
var container = data;
|
|
|
|
$scope.container = container;
|
|
|
|
startLogPolling(!container.Config.Tty);
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
Notifications.error('Failure', err, 'Unable to retrieve container information');
|
|
|
|
});
|
|
|
|
}
|
2015-02-05 19:23:57 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
initView();
|
|
|
|
},
|
|
|
|
]);
|