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