portainer/app/components/containerLogs/containerLogsController.js

77 lines
2.4 KiB
JavaScript
Raw Normal View History

2014-12-15 22:26:10 +00:00
angular.module('containerLogs', [])
.controller('ContainerLogsController', ['$scope', '$routeParams', '$location', '$anchorScroll', 'ContainerLogs', 'Container', 'ViewSpinner',
function($scope, $routeParams, $location, $anchorScroll, ContainerLogs, Container, ViewSpinner) {
2015-01-04 00:39:40 +00:00
$scope.stdout = '';
2014-12-15 22:26:10 +00:00
$scope.stderr = '';
$scope.showTimestamps = false;
$scope.tailLines = 2000;
2014-12-15 22:26:10 +00:00
ViewSpinner.spin();
Container.get({id: $routeParams.id}, function(d) {
$scope.container = d;
ViewSpinner.stop();
}, function(e) {
if (e.status === 404) {
Messages.error("Not found", "Container not found.");
} else {
Messages.error("Failure", e.data);
}
ViewSpinner.stop();
});
function getLogs() {
2015-02-21 18:09:12 +00:00
ViewSpinner.spin();
ContainerLogs.get($routeParams.id, {
stdout: 1,
stderr: 0,
timestamps: $scope.showTimestamps,
tail: $scope.tailLines
}, function(data, status, headers, config) {
// Replace carriage returns with newlines to clean up output
2015-03-08 17:19:51 +00:00
data = data.replace(/[\r]/g, '\n');
// Strip 8 byte header from each line of output
data = data.substring(8);
data = data.replace(/\n(.{8})/g, '\n');
$scope.stdout = data;
2015-02-21 18:09:12 +00:00
ViewSpinner.stop();
2014-12-15 22:26:10 +00:00
});
2015-02-21 18:09:12 +00:00
2015-02-16 17:42:02 +00:00
ContainerLogs.get($routeParams.id, {
stdout: 0,
stderr: 1,
timestamps: $scope.showTimestamps,
tail: $scope.tailLines
}, function(data, status, headers, config) {
// Replace carriage returns with newlines to clean up output
2015-03-08 17:19:51 +00:00
data = data.replace(/[\r]/g, '\n');
// Strip 8 byte header from each line of output
data = data.substring(8);
data = data.replace(/\n(.{8})/g, '\n');
$scope.stderr = data;
2015-02-21 18:09:12 +00:00
ViewSpinner.stop();
2014-12-15 22:26:10 +00:00
});
}
// initial call
getLogs();
var logIntervalId = window.setInterval(getLogs, 5000);
$scope.$on("$destroy", function(){
// clearing interval when view changes
clearInterval(logIntervalId);
});
$scope.scrollTo = function(id) {
$location.hash(id);
$anchorScroll();
2015-01-04 00:39:40 +00:00
};
2014-12-15 22:26:10 +00:00
$scope.toggleTimestamps = function() {
2015-01-04 00:39:40 +00:00
getLogs();
};
$scope.toggleTail = function() {
getLogs();
};
2014-12-15 22:26:10 +00:00
}]);