Allow to follow app logs
This commit is contained in:
@@ -1,32 +1,29 @@
|
||||
<div class="content support">
|
||||
<br/>
|
||||
<br/>
|
||||
|
||||
<div>
|
||||
<div class="text-left">
|
||||
<h1>Logs</h1>
|
||||
</div>
|
||||
</div>
|
||||
<div class="row">
|
||||
<div class="col-md-10 col-md-offset-1">
|
||||
<h1>Logs</h1>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="card card-large">
|
||||
<div class="grid-item-top">
|
||||
<div class="row animateMeOpacity">
|
||||
<div class="col-lg-12">
|
||||
<h3>Logs</h3>
|
||||
Select the log to view
|
||||
<br/>
|
||||
<br/>
|
||||
<form name="logsForm">
|
||||
<div class="form-group">
|
||||
<select class="form-control" name="type" style="width: 50%;" ng-model="logs.selectedUrl" required>
|
||||
<option ng-repeat="log in logs.types" ng-value="log.url">{{ log.name }}</option>
|
||||
</select>
|
||||
</div>
|
||||
<a class="btn btn-primary" ng-disabled="!logs.selectedUrl" ng-href="{{logs.selectedUrl}}&format=short&lines=800" target="_self"> Download </a>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<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>
|
||||
</div>
|
||||
<div class="pagination pull-right">
|
||||
<button class="btn btn-default btn-outline" ng-click=""><i class="fa fa-download"></i> Download </button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-md-10 col-md-offset-1">
|
||||
<div class="card card-block log-line-container">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Offset the footer -->
|
||||
|
||||
@@ -4,22 +4,56 @@ angular.module('Application').controller('LogsController', ['$scope', '$location
|
||||
$scope.config = Client.getConfig();
|
||||
$scope.user = Client.getUserInfo();
|
||||
|
||||
$scope.logs = {
|
||||
types: null,
|
||||
selectedUrl: '' // index into types
|
||||
};
|
||||
$scope.logs = [];
|
||||
$scope.selected = null;
|
||||
|
||||
function ab2str(buf) {
|
||||
return String.fromCharCode.apply(null, new Uint16Array(buf));
|
||||
}
|
||||
|
||||
$scope.populateLogTypes = function () {
|
||||
$scope.logs.types = [
|
||||
{ name: 'System (All)', url: Client.makeURL('/api/v1/cloudron/logs?units=all') },
|
||||
{ name: 'Box', url: Client.makeURL('/api/v1/cloudron/logs?units=box') },
|
||||
{ name: 'Mail', url: Client.makeURL('/api/v1/cloudron/logs?units=mail') }
|
||||
];
|
||||
$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' });
|
||||
|
||||
Client.getInstalledApps().forEach(function (app) {
|
||||
$scope.logs.types.push({ name: app.fqdn, url: Client.makeURL('/api/v1/apps/' + app.id + '/logs') });
|
||||
$scope.logs.types.push({ name: app.fqdn, type: 'app', id: app.id });
|
||||
});
|
||||
};
|
||||
|
||||
$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);
|
||||
};
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
Client.onReady($scope.populateLogTypes);
|
||||
}]);
|
||||
|
||||
Reference in New Issue
Block a user