2017-07-08 09:34:21 +00:00
|
|
|
angular.module('serviceLogs', [])
|
2017-09-21 14:00:53 +00:00
|
|
|
.controller('ServiceLogsController', ['$scope', '$transition$', '$anchorScroll', 'ServiceLogs', 'Service',
|
|
|
|
function ($scope, $transition$, $anchorScroll, ServiceLogs, Service) {
|
2017-07-08 09:34:21 +00:00
|
|
|
$scope.state = {};
|
|
|
|
$scope.state.displayTimestampsOut = false;
|
|
|
|
$scope.state.displayTimestampsErr = false;
|
|
|
|
$scope.stdout = '';
|
|
|
|
$scope.stderr = '';
|
|
|
|
$scope.tailLines = 2000;
|
|
|
|
|
|
|
|
function getLogs() {
|
|
|
|
$('#loadingViewSpinner').show();
|
|
|
|
getLogsStdout();
|
|
|
|
getLogsStderr();
|
|
|
|
$('#loadingViewSpinner').hide();
|
|
|
|
}
|
|
|
|
|
|
|
|
function getLogsStderr() {
|
2017-09-21 14:00:53 +00:00
|
|
|
ServiceLogs.get($transition$.params().id, {
|
2017-07-08 09:34:21 +00:00
|
|
|
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;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function getLogsStdout() {
|
2017-09-21 14:00:53 +00:00
|
|
|
ServiceLogs.get($transition$.params().id, {
|
2017-07-08 09:34:21 +00:00
|
|
|
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;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function getService() {
|
|
|
|
$('#loadingViewSpinner').show();
|
2017-09-21 14:00:53 +00:00
|
|
|
Service.get({id: $transition$.params().id}, function (d) {
|
2017-07-08 09:34:21 +00:00
|
|
|
$scope.service = d;
|
|
|
|
$('#loadingViewSpinner').hide();
|
|
|
|
}, function (e) {
|
|
|
|
Notifications.error('Failure', e, 'Unable to retrieve service info');
|
|
|
|
$('#loadingViewSpinner').hide();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
function initView() {
|
|
|
|
getService();
|
|
|
|
getLogs();
|
|
|
|
|
|
|
|
var logIntervalId = window.setInterval(getLogs, 5000);
|
|
|
|
|
|
|
|
$scope.$on('$destroy', function () {
|
|
|
|
// clearing interval when view changes
|
|
|
|
clearInterval(logIntervalId);
|
|
|
|
});
|
|
|
|
|
|
|
|
$scope.toggleTimestampsOut = function () {
|
|
|
|
getLogsStdout();
|
|
|
|
};
|
|
|
|
|
|
|
|
$scope.toggleTimestampsErr = function () {
|
|
|
|
getLogsStderr();
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
initView();
|
|
|
|
|
|
|
|
}]);
|