Fix the platform log streaming
This commit is contained in:
@@ -573,10 +573,10 @@ angular.module('Application').service('Client', ['$http', 'md5', 'Notification',
|
||||
|
||||
Client.prototype.getPlatformLogs = function (units, follow, callback) {
|
||||
if (follow) {
|
||||
var eventSource = new EventSource(client.apiOrigin + '/api/v1/cloudron/logstream?lines=100&access_token=' + token);
|
||||
var eventSource = new EventSource(client.apiOrigin + '/api/v1/cloudron/logstream?lines=10&access_token=' + token + '&units=' + units);
|
||||
callback(null, eventSource);
|
||||
} else {
|
||||
get('/api/v1/apps/' + appId + '/logs').success(function (data, status) {
|
||||
get('/api/v1/cloudron/logs?lines=100&units=' + units).success(function (data, status) {
|
||||
if (status !== 200 || typeof data !== 'object') return callback(new ClientError(status, data));
|
||||
callback(null, data);
|
||||
}).error(defaultErrorHandler(callback));
|
||||
@@ -592,7 +592,7 @@ angular.module('Application').service('Client', ['$http', 'md5', 'Notification',
|
||||
|
||||
Client.prototype.getAppLogs = function (appId, follow, callback) {
|
||||
if (follow) {
|
||||
var eventSource = new EventSource(client.apiOrigin + '/api/v1/apps/' + appId + '/logstream?lines=100&access_token=' + token);
|
||||
var eventSource = new EventSource(client.apiOrigin + '/api/v1/apps/' + appId + '/logstream?lines=10&access_token=' + token);
|
||||
callback(null, eventSource);
|
||||
} else {
|
||||
get('/api/v1/apps/' + appId + '/logs').success(function (data, status) {
|
||||
|
||||
@@ -9,9 +9,7 @@
|
||||
<div class="row">
|
||||
<div class="col-md-10 col-md-offset-1">
|
||||
<div class="filter">
|
||||
<select class="form-control" name="type" ng-model="logs.units" required>
|
||||
<option ng-repeat="log in logs.types" ng-value="log.units">{{ log.name }}</option>
|
||||
</select>
|
||||
<select class="form-control" ng-options="log.name for log in logs track by log.value" ng-model="selected"></select>
|
||||
</div>
|
||||
<div class="pagination pull-right">
|
||||
<button class="btn btn-default btn-outline" ng-click=""><i class="fa fa-download"></i> Download </button>
|
||||
|
||||
@@ -5,54 +5,56 @@ angular.module('Application').controller('LogsController', ['$scope', '$location
|
||||
$scope.user = Client.getUserInfo();
|
||||
|
||||
$scope.logs = [];
|
||||
$scope.selected = null;
|
||||
$scope.selected = '';
|
||||
$scope.activeEventSource = null;
|
||||
|
||||
function ab2str(buf) {
|
||||
return String.fromCharCode.apply(null, new Uint16Array(buf));
|
||||
}
|
||||
|
||||
$scope.populateLogTypes = function () {
|
||||
$scope.logs.push({ name: 'System (All)', type: 'platform', units: 'all' });
|
||||
$scope.logs.push({ name: 'Box', type: 'platform', units: 'box' });
|
||||
$scope.logs.push({ name: 'Mail', type: 'platform', units: 'mail' });
|
||||
$scope.logs.push({ name: 'System (All)', type: 'platform', value: 'all' });
|
||||
$scope.logs.push({ name: 'Box', type: 'platform', value: 'box' });
|
||||
$scope.logs.push({ name: 'Mail', type: 'platform', value: 'mail' });
|
||||
|
||||
Client.getInstalledApps().forEach(function (app) {
|
||||
$scope.logs.types.push({ name: app.fqdn, type: 'app', id: app.id });
|
||||
$scope.logs.push({ name: app.fqdn, type: 'app', value: app.id });
|
||||
});
|
||||
|
||||
$scope.selected = $scope.logs[0];
|
||||
};
|
||||
|
||||
$scope.$watch('selected', function (newVal) {
|
||||
if (!newVal) return;
|
||||
|
||||
if (newVal.type === 'platform') {
|
||||
Client.getPlatformLogs(newVal.units, true, function (error, result) {
|
||||
if (error) return console.error(error);
|
||||
|
||||
var logViewer = $('.log-line-container');
|
||||
logViewer.empty();
|
||||
});
|
||||
} else {
|
||||
Client.getAppLogs(newVal.id, true, function (error, result) {
|
||||
if (error) return console.error(error);
|
||||
|
||||
var logViewer = $('.log-line-container');
|
||||
logViewer.empty();
|
||||
|
||||
result.onmessage = function (e) {
|
||||
var data;
|
||||
|
||||
try {
|
||||
data = JSON.parse(e.data);
|
||||
} catch (e) {
|
||||
return console.error(e);
|
||||
}
|
||||
|
||||
var logLine = $('<div>');
|
||||
logLine.html(window.ansiToHTML(ab2str(data.message)));
|
||||
logViewer.append(logLine);
|
||||
};
|
||||
});
|
||||
// close the old event source so we wont receive any new logs
|
||||
if ($scope.activeEventSource) {
|
||||
$scope.activeEventSource.close();
|
||||
$scope.activeEventSource = null;
|
||||
}
|
||||
|
||||
var func = newVal.type === 'platform' ? Client.getPlatformLogs : Client.getAppLogs;
|
||||
func(newVal.value, true, function handleLogs(error, result) {
|
||||
if (error) return console.error(error);
|
||||
|
||||
var logViewer = $('.log-line-container');
|
||||
logViewer.empty();
|
||||
|
||||
$scope.activeEventSource = result;
|
||||
result.onmessage = function handleMessage(message) {
|
||||
var data;
|
||||
|
||||
try {
|
||||
data = JSON.parse(message.data);
|
||||
} catch (e) {
|
||||
return console.error(e);
|
||||
}
|
||||
|
||||
var logLine = $('<div>');
|
||||
logLine.html(window.ansiToHTML(ab2str(data.message)));
|
||||
logViewer.append(logLine);
|
||||
};
|
||||
});
|
||||
});
|
||||
|
||||
Client.onReady($scope.populateLogTypes);
|
||||
|
||||
Reference in New Issue
Block a user