mirror of https://github.com/portainer/portainer
feat(k8s/logs): Add the ability to download application/stack logs (#4046)
* feat(logs): Add the ability to download application/stack logs * feat(kubernetes): minor UI update Co-authored-by: Anthony Lapenna <lapenna.anthony@gmail.com>pull/4053/head
parent
a452599829
commit
c9e8021fe8
|
@ -46,6 +46,13 @@
|
|||
</div>
|
||||
</div>
|
||||
<!-- !search -->
|
||||
<!-- actions -->
|
||||
<div class="form-group">
|
||||
<div class="col-sm-12">
|
||||
<button class="btn btn-primary btn-sm" type="button" ng-click="ctrl.downloadLogs()" style="margin-left: 0;"><i class="fa fa-download"></i> Download logs</button>
|
||||
</div>
|
||||
</div>
|
||||
<!-- !actions -->
|
||||
</form>
|
||||
</rd-widget-body>
|
||||
</rd-widget>
|
||||
|
|
|
@ -1,14 +1,17 @@
|
|||
import angular from 'angular';
|
||||
import _ from 'lodash-es';
|
||||
|
||||
class KubernetesApplicationLogsController {
|
||||
/* @ngInject */
|
||||
constructor($async, $state, $interval, Notifications, KubernetesApplicationService, KubernetesPodService) {
|
||||
constructor($async, $state, $interval, Notifications, KubernetesApplicationService, KubernetesPodService, Blob, FileSaver) {
|
||||
this.$async = $async;
|
||||
this.$state = $state;
|
||||
this.$interval = $interval;
|
||||
this.Notifications = Notifications;
|
||||
this.KubernetesApplicationService = KubernetesApplicationService;
|
||||
this.KubernetesPodService = KubernetesPodService;
|
||||
this.Blob = Blob;
|
||||
this.FileSaver = FileSaver;
|
||||
|
||||
this.onInit = this.onInit.bind(this);
|
||||
this.stopRepeater = this.stopRepeater.bind(this);
|
||||
|
@ -35,6 +38,11 @@ class KubernetesApplicationLogsController {
|
|||
this.repeater = this.$interval(this.getApplicationLogsAsync, this.state.refreshRate);
|
||||
}
|
||||
|
||||
downloadLogs() {
|
||||
const data = new this.Blob([_.reduce(this.applicationLogs, (acc, log) => acc + '\n' + log, '')]);
|
||||
this.FileSaver.saveAs(data, this.podName + '_logs.txt');
|
||||
}
|
||||
|
||||
async getApplicationLogsAsync() {
|
||||
try {
|
||||
this.applicationLogs = await this.KubernetesPodService.logs(this.application.ResourcePool, this.podName);
|
||||
|
|
|
@ -44,6 +44,13 @@
|
|||
</div>
|
||||
</div>
|
||||
<!-- !search -->
|
||||
<!-- actions -->
|
||||
<div class="form-group">
|
||||
<div class="col-sm-12">
|
||||
<button class="btn btn-primary btn-sm" type="button" ng-click="ctrl.downloadLogs()" style="margin-left: 0;"><i class="fa fa-download"></i> Download logs</button>
|
||||
</div>
|
||||
</div>
|
||||
<!-- !actions -->
|
||||
</form>
|
||||
</rd-widget-body>
|
||||
</rd-widget>
|
||||
|
|
|
@ -6,13 +6,15 @@ const colors = ['red', 'orange', 'lime', 'green', 'darkgreen', 'cyan', 'turquois
|
|||
|
||||
class KubernetesStackLogsController {
|
||||
/* @ngInject */
|
||||
constructor($async, $state, $interval, Notifications, KubernetesApplicationService, KubernetesPodService) {
|
||||
constructor($async, $state, $interval, Notifications, KubernetesApplicationService, KubernetesPodService, FileSaver, Blob) {
|
||||
this.$async = $async;
|
||||
this.$state = $state;
|
||||
this.$interval = $interval;
|
||||
this.Notifications = Notifications;
|
||||
this.KubernetesApplicationService = KubernetesApplicationService;
|
||||
this.KubernetesPodService = KubernetesPodService;
|
||||
this.Blob = Blob;
|
||||
this.FileSaver = FileSaver;
|
||||
|
||||
this.onInit = this.onInit.bind(this);
|
||||
this.stopRepeater = this.stopRepeater.bind(this);
|
||||
|
@ -87,6 +89,11 @@ class KubernetesStackLogsController {
|
|||
}
|
||||
}
|
||||
|
||||
downloadLogs() {
|
||||
const data = new this.Blob([(this.dataLogs = _.reduce(this.stackLogs, (acc, log) => acc + '\n' + log.AppName + ' ' + log.Line, ''))]);
|
||||
this.FileSaver.saveAs(data, this.state.transition.name + '_logs.txt');
|
||||
}
|
||||
|
||||
async onInit() {
|
||||
this.state = {
|
||||
autoRefresh: false,
|
||||
|
|
Loading…
Reference in New Issue