2014-12-15 22:26:10 +00:00
|
|
|
angular.module('containerLogs', [])
|
2016-07-07 00:44:58 +00:00
|
|
|
.controller('ContainerLogsController', ['$scope', '$stateParams', '$anchorScroll', 'ContainerLogs', 'Container',
|
|
|
|
function ($scope, $stateParams, $anchorScroll, ContainerLogs, Container) {
|
2016-06-02 05:34:03 +00:00
|
|
|
$scope.state = {};
|
|
|
|
$scope.state.displayTimestampsOut = false;
|
|
|
|
$scope.state.displayTimestampsErr = false;
|
|
|
|
$scope.stdout = '';
|
|
|
|
$scope.stderr = '';
|
|
|
|
$scope.tailLines = 2000;
|
2014-12-15 22:26:10 +00:00
|
|
|
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#loadingViewSpinner').show();
|
2016-06-02 05:34:03 +00:00
|
|
|
Container.get({id: $stateParams.id}, function (d) {
|
|
|
|
$scope.container = d;
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#loadingViewSpinner').hide();
|
2016-06-02 05:34:03 +00:00
|
|
|
}, function (e) {
|
|
|
|
if (e.status === 404) {
|
|
|
|
Messages.error("Not found", "Container not found.");
|
|
|
|
} else {
|
|
|
|
Messages.error("Failure", e.data);
|
|
|
|
}
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#loadingViewSpinner').hide();
|
2016-06-02 05:34:03 +00:00
|
|
|
});
|
2014-12-15 22:26:10 +00:00
|
|
|
|
2016-06-02 05:34:03 +00:00
|
|
|
function getLogs() {
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#loadingViewSpinner').show();
|
2016-06-02 05:34:03 +00:00
|
|
|
getLogsStdout();
|
|
|
|
getLogsStderr();
|
2016-07-07 00:44:58 +00:00
|
|
|
$('#loadingViewSpinner').hide();
|
2016-06-02 05:34:03 +00:00
|
|
|
}
|
2015-02-21 18:09:12 +00:00
|
|
|
|
2016-06-02 05:34:03 +00:00
|
|
|
function getLogsStderr() {
|
|
|
|
ContainerLogs.get($stateParams.id, {
|
|
|
|
stdout: 0,
|
|
|
|
stderr: 1,
|
|
|
|
timestamps: $scope.state.displayTimestampsErr,
|
|
|
|
tail: $scope.tailLines
|
|
|
|
}, function (data, status, headers, config) {
|
|
|
|
// Replace carriage returns with newlines to clean up output
|
|
|
|
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;
|
|
|
|
});
|
|
|
|
}
|
2014-12-15 22:26:10 +00:00
|
|
|
|
2016-06-02 05:34:03 +00:00
|
|
|
function getLogsStdout() {
|
|
|
|
ContainerLogs.get($stateParams.id, {
|
|
|
|
stdout: 1,
|
|
|
|
stderr: 0,
|
|
|
|
timestamps: $scope.state.displayTimestampsOut,
|
|
|
|
tail: $scope.tailLines
|
|
|
|
}, function (data, status, headers, config) {
|
|
|
|
// Replace carriage returns with newlines to clean up output
|
|
|
|
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;
|
|
|
|
});
|
|
|
|
}
|
2014-12-15 22:26:10 +00:00
|
|
|
|
2016-06-02 05:34:03 +00:00
|
|
|
// initial call
|
|
|
|
getLogs();
|
|
|
|
var logIntervalId = window.setInterval(getLogs, 5000);
|
2014-12-15 22:26:10 +00:00
|
|
|
|
2016-06-02 05:34:03 +00:00
|
|
|
$scope.$on("$destroy", function () {
|
|
|
|
// clearing interval when view changes
|
|
|
|
clearInterval(logIntervalId);
|
|
|
|
});
|
2014-12-15 22:26:10 +00:00
|
|
|
|
2016-06-02 05:34:03 +00:00
|
|
|
$scope.toggleTimestampsOut = function () {
|
|
|
|
getLogsStdout();
|
|
|
|
};
|
2015-02-05 19:23:57 +00:00
|
|
|
|
2016-06-02 05:34:03 +00:00
|
|
|
$scope.toggleTimestampsErr = function () {
|
|
|
|
getLogsStderr();
|
|
|
|
};
|
|
|
|
}]);
|