Use addon log routes in logviewer

This commit is contained in:
Johannes Zellner
2018-11-26 14:49:50 +01:00
parent ae488312a1
commit 8bd9237951
2 changed files with 22 additions and 6 deletions

View File

@@ -653,6 +653,18 @@ angular.module('Application').service('Client', ['$http', '$interval', 'md5', 'N
}
};
Client.prototype.getAddonLogs = function (addonName, follow, lines, callback) {
if (follow) {
var eventSource = new EventSource(client.apiOrigin + '/api/v1/addons/' + addonName + '/logstream?lines=' + lines + '&access_token=' + token);
callback(null, eventSource);
} else {
get('/api/v1/addons/' + addonName + '/logs?lines=100').success(function (data, status) {
if (status !== 200 || typeof data !== 'object') return callback(new ClientError(status, data));
callback(null, data);
}).error(defaultErrorHandler(callback));
}
};
Client.prototype.getApps = function (callback) {
get('/api/v1/apps').success(function (data, status) {
if (status !== 200 || typeof data !== 'object') return callback(new ClientError(status, data));

View File

@@ -32,7 +32,11 @@ app.controller('LogsController', ['$scope', '$timeout', '$location', 'Client', f
function showLogs() {
if (!$scope.selected) return;
var func = $scope.selected.type === 'platform' ? Client.getPlatformLogs : Client.getAppLogs;
var func;
if ($scope.selected.type === 'platform') func = Client.getPlatformLogs;
else if ($scope.selected.type === 'addon') func = Client.getAddonLogs;
else func = Client.getAppLogs;
func($scope.selected.value, true, $scope.lines, function handleLogs(error, result) {
if (error) return console.error(error);
@@ -66,11 +70,11 @@ app.controller('LogsController', ['$scope', '$timeout', '$location', 'Client', f
{ name: 'Box', type: 'platform', value: 'box', url: Client.makeURL('/api/v1/cloudron/logs/box') },
{ name: 'Mail', type: 'platform', value: 'mail', url: Client.makeURL('/api/v1/cloudron/logs/mail') },
{ name: 'Backup', type: 'platform', value: 'backup', url: Client.makeURL('/api/v1/cloudron/logs/backup') },
{ name: 'MongoDB', type: 'platform', value: 'mongodb', url: Client.makeURL('/api/v1/addons/mongodb/logs') },
{ name: 'MySQL', type: 'platform', value: 'mysql', url: Client.makeURL('/api/v1/addons/mysql/logs') },
{ name: 'PostgreSQL', type: 'platform', value: 'postgresql', url: Client.makeURL('/api/v1/addons/postgresql/logs') },
{ name: 'Email', type: 'platform', value: 'email', url: Client.makeURL('/api/v1/addons/email/logs') },
{ name: 'Docker', type: 'platform', value: 'docker', url: Client.makeURL('/api/v1/addons/docker/logs') }
{ name: 'MongoDB', type: 'addon', value: 'mongodb', url: Client.makeURL('/api/v1/addons/mongodb/logs') },
{ name: 'MySQL', type: 'addon', value: 'mysql', url: Client.makeURL('/api/v1/addons/mysql/logs') },
{ name: 'PostgreSQL', type: 'addon', value: 'postgresql', url: Client.makeURL('/api/v1/addons/postgresql/logs') },
{ name: 'Email', type: 'addon', value: 'email', url: Client.makeURL('/api/v1/addons/email/logs') },
{ name: 'Docker', type: 'addon', value: 'docker', url: Client.makeURL('/api/v1/addons/docker/logs') }
];
$scope.selected = BUILT_IN_LOGS.find(function (e) { return e.value === id; });