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('ServiceLogsController', [
|
|
|
|
'$scope',
|
|
|
|
'$transition$',
|
|
|
|
'$interval',
|
|
|
|
'ServiceService',
|
|
|
|
'Notifications',
|
|
|
|
function ($scope, $transition$, $interval, ServiceService, Notifications) {
|
|
|
|
$scope.state = {
|
|
|
|
refreshRate: 3,
|
|
|
|
lineCount: 100,
|
|
|
|
sinceTimestamp: '',
|
|
|
|
displayTimestamps: false,
|
|
|
|
};
|
2017-07-08 09:34:21 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
$scope.changeLogCollection = function (logCollectionStatus) {
|
|
|
|
if (!logCollectionStatus) {
|
|
|
|
stopRepeater();
|
|
|
|
} else {
|
|
|
|
setUpdateRepeater();
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.$on('$destroy', function () {
|
2018-02-28 06:19:28 +00:00
|
|
|
stopRepeater();
|
2020-04-10 21:54:53 +00:00
|
|
|
});
|
2017-07-08 09:34:21 +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;
|
|
|
|
}
|
|
|
|
}
|
2018-02-28 06:19:28 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
function setUpdateRepeater() {
|
|
|
|
var refreshRate = $scope.state.refreshRate;
|
|
|
|
$scope.repeater = $interval(function () {
|
|
|
|
ServiceService.logs($transition$.params().id, 1, 1, $scope.state.displayTimestamps ? 1 : 0, moment($scope.state.sinceTimestamp).unix(), $scope.state.lineCount)
|
|
|
|
.then(function success(data) {
|
|
|
|
$scope.logs = data;
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
stopRepeater();
|
|
|
|
Notifications.error('Failure', err, 'Unable to retrieve service logs');
|
|
|
|
});
|
|
|
|
}, refreshRate * 1000);
|
2018-02-28 06:19:28 +00:00
|
|
|
}
|
2017-07-08 09:34:21 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
function startLogPolling() {
|
2018-10-29 04:49:35 +00:00
|
|
|
ServiceService.logs($transition$.params().id, 1, 1, $scope.state.displayTimestamps ? 1 : 0, moment($scope.state.sinceTimestamp).unix(), $scope.state.lineCount)
|
2020-04-10 21:54:53 +00:00
|
|
|
.then(function success(data) {
|
|
|
|
$scope.logs = data;
|
|
|
|
setUpdateRepeater();
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
stopRepeater();
|
|
|
|
Notifications.error('Failure', err, 'Unable to retrieve service logs');
|
|
|
|
});
|
|
|
|
}
|
2017-07-08 09:34:21 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
function initView() {
|
|
|
|
ServiceService.service($transition$.params().id)
|
|
|
|
.then(function success(data) {
|
|
|
|
$scope.service = data;
|
|
|
|
startLogPolling();
|
|
|
|
})
|
|
|
|
.catch(function error(err) {
|
|
|
|
Notifications.error('Failure', err, 'Unable to retrieve service information');
|
|
|
|
});
|
|
|
|
}
|
2017-07-08 09:34:21 +00:00
|
|
|
|
2020-04-10 21:54:53 +00:00
|
|
|
initView();
|
|
|
|
},
|
|
|
|
]);
|