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