mirror of
https://github.com/portainer/portainer.git
synced 2025-07-25 08:19:40 +02:00
fix(logging): default to pretty logging [EE-4371] (#7847)
* fix(logging): default to pretty logging EE-4371 * feat(app/logs): prettify stack traces in JSON logs * feat(nomad/logs): prettify JSON logs in log viewer * feat(kubernetes/logs): prettigy JSON logs in log viewers * feat(app/logs): format and color zerolog prettified logs * fix(app/logs): pre-parse logs when they are double serialized Co-authored-by: andres-portainer <andres-portainer@users.noreply.github.com> Co-authored-by: LP B <xAt0mZ@users.noreply.github.com>
This commit is contained in:
parent
ee5600b6af
commit
535a26412f
27 changed files with 935 additions and 279 deletions
|
@ -67,7 +67,7 @@ class KubernetesPodService {
|
|||
params.container = containerName;
|
||||
}
|
||||
const data = await this.KubernetesPods(namespace).logs(params).$promise;
|
||||
return data.logs.length === 0 ? [] : data.logs.split('\n');
|
||||
return data.logs;
|
||||
} catch (err) {
|
||||
throw new PortainerError('Unable to retrieve pod logs', err);
|
||||
}
|
||||
|
|
|
@ -77,9 +77,10 @@
|
|||
|
||||
<div class="row">
|
||||
<div class="col-sm-12 h-[max(400px,calc(100vh-380px))]">
|
||||
<pre
|
||||
class="log_viewer widget"
|
||||
><div ng-repeat="line in ctrl.state.filteredLogs = (ctrl.applicationLogs | filter:ctrl.state.search) track by $index" class="line" ng-if="line"><p class="inner_line">{{ line }}</p></div><div ng-if="ctrl.applicationLogs.length && !ctrl.state.filteredLogs.length" class="line"><p class="inner_line">No log line matching the '{{ ctrl.state.search }}' filter</p></div><div ng-if="ctrl.applicationLogs.length === 0" class="line"><p class="inner_line">No logs available</p></div></pre>
|
||||
<pre class="log_viewer widget">
|
||||
<div ng-repeat="log in ctrl.state.filteredLogs = (ctrl.applicationLogs | filter:{ 'line': ctrl.state.search }) track by $index" class="line" ng-if="log.line"><p class="inner_line"><span ng-repeat="span in log.spans track by $index" ng-style="{ 'color': span.fgColor, 'background-color': span.bgColor, 'font-weight': span.fontWeight }">{{ span.text }}</span></p></div>
|
||||
<div ng-if="ctrl.applicationLogs.length && !ctrl.state.filteredLogs.length" class="line"><p class="inner_line">No log line matching the '{{ ctrl.state.search }}' filter</p></div>
|
||||
<div ng-if="ctrl.applicationLogs.length === 0" class="line"><p class="inner_line">No logs available</p></div></pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
import angular from 'angular';
|
||||
import _ from 'lodash-es';
|
||||
|
||||
import { concatLogsToString, formatLogs } from '@/docker/helpers/logHelper';
|
||||
|
||||
class KubernetesApplicationLogsController {
|
||||
/* @ngInject */
|
||||
|
@ -39,13 +40,15 @@ class KubernetesApplicationLogsController {
|
|||
}
|
||||
|
||||
downloadLogs() {
|
||||
const data = new this.Blob([_.reduce(this.applicationLogs, (acc, log) => acc + '\n' + log, '')]);
|
||||
const logsAsString = concatLogsToString(this.applicationLogs);
|
||||
const data = new this.Blob([logsAsString]);
|
||||
this.FileSaver.saveAs(data, this.podName + '_logs.txt');
|
||||
}
|
||||
|
||||
async getApplicationLogsAsync() {
|
||||
try {
|
||||
this.applicationLogs = await this.KubernetesPodService.logs(this.application.ResourcePool, this.podName, this.containerName);
|
||||
const rawLogs = await this.KubernetesPodService.logs(this.application.ResourcePool, this.podName, this.containerName);
|
||||
this.applicationLogs = formatLogs(rawLogs);
|
||||
} catch (err) {
|
||||
this.stopRepeater();
|
||||
this.Notifications.error('Failure', err, 'Unable to retrieve application logs');
|
||||
|
@ -70,13 +73,8 @@ class KubernetesApplicationLogsController {
|
|||
this.containerName = containerName;
|
||||
|
||||
try {
|
||||
const [application, applicationLogs] = await Promise.all([
|
||||
this.KubernetesApplicationService.get(namespace, applicationName),
|
||||
this.KubernetesPodService.logs(namespace, podName, containerName),
|
||||
]);
|
||||
|
||||
this.application = application;
|
||||
this.applicationLogs = applicationLogs;
|
||||
this.application = await this.KubernetesApplicationService.get(namespace, applicationName);
|
||||
await this.getApplicationLogsAsync();
|
||||
} catch (err) {
|
||||
this.Notifications.error('Failure', err, 'Unable to retrieve application logs');
|
||||
} finally {
|
||||
|
|
|
@ -69,9 +69,11 @@ ctrl.state.transition.name,
|
|||
|
||||
<div class="row">
|
||||
<div class="col-sm-12 h-[max(400px,calc(100vh-380px))]">
|
||||
<pre
|
||||
class="log_viewer"
|
||||
><div ng-repeat="line in ctrl.state.filteredLogs = (ctrl.stackLogs | filter:ctrl.state.search) track by $index" class="line" ng-if="line"><p class="inner_line"><span ng-style="{'color': line.Color, 'font-weight': 'bold'};">{{ line.AppName }}</span> {{ line.Line }}</p></div><div ng-if="ctrl.stackLogs.length && !ctrl.state.filteredLogs.length" class="line"><p class="inner_line">No log line matching the '{{ ctrl.state.search }}' filter</p></div><div ng-if="ctrl.stackLogs.length === 0" class="line"><p class="inner_line">No logs available</p></div></pre>
|
||||
<pre class="log_viewer">
|
||||
<div ng-repeat="log in ctrl.state.filteredLogs = (ctrl.stackLogs | filter:{ 'line': ctrl.state.search }) track by $index" class="line" ng-if="log.line"><p class="inner_line"><span ng-style="{'color': log.appColor, 'font-weight': 'bold'};">{{ log.appName }}</span> <span ng-repeat="span in log.spans track by $index" ng-style="{ 'color': span.fgColor, 'background-color': span.bgColor, 'font-weight': span.fontWeight }">{{ span.text }}</span></p></div>
|
||||
<div ng-if="ctrl.stackLogs.length && !ctrl.state.filteredLogs.length" class="line"><p class="inner_line">No log line matching the '{{ ctrl.state.search }}' filter</p></div>
|
||||
<div ng-if="ctrl.stackLogs.length === 0" class="line"><p class="inner_line">No logs available</p></div>
|
||||
</pre>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
import _ from 'lodash-es';
|
||||
import { filter, flatMap, map } from 'lodash';
|
||||
import angular from 'angular';
|
||||
import $allSettled from 'Portainer/services/allSettled';
|
||||
import { concatLogsToString, formatLogs } from '@/docker/helpers/logHelper';
|
||||
|
||||
const colors = ['red', 'orange', 'lime', 'green', 'darkgreen', 'cyan', 'turquoise', 'teal', 'deepskyblue', 'blue', 'darkblue', 'slateblue', 'magenta', 'darkviolet'];
|
||||
|
||||
|
@ -58,7 +59,7 @@ class KubernetesStackLogsController {
|
|||
Pods: [],
|
||||
};
|
||||
|
||||
const promises = _.flatMap(_.map(app.Pods, (pod) => _.map(pod.Containers, (container) => this.generateLogsPromise(pod, container))));
|
||||
const promises = flatMap(map(app.Pods, (pod) => map(pod.Containers, (container) => this.generateLogsPromise(pod, container))));
|
||||
const result = await $allSettled(promises);
|
||||
res.Pods = result.fulfilled;
|
||||
return res;
|
||||
|
@ -67,21 +68,12 @@ class KubernetesStackLogsController {
|
|||
async getStackLogsAsync() {
|
||||
try {
|
||||
const applications = await this.KubernetesApplicationService.get(this.state.transition.namespace);
|
||||
const filteredApplications = _.filter(applications, (app) => app.StackName === this.state.transition.name);
|
||||
const logsPromises = _.map(filteredApplications, this.generateAppPromise);
|
||||
const filteredApplications = filter(applications, (app) => app.StackName === this.state.transition.name);
|
||||
const logsPromises = map(filteredApplications, this.generateAppPromise);
|
||||
const data = await Promise.all(logsPromises);
|
||||
const logs = _.flatMap(data, (app, index) => {
|
||||
return _.flatMap(app.Pods, (pod) => {
|
||||
return _.map(pod.Logs, (line) => {
|
||||
const res = {
|
||||
Color: colors[index % colors.length],
|
||||
Line: line,
|
||||
AppName: pod.Pod.Name,
|
||||
};
|
||||
return res;
|
||||
});
|
||||
});
|
||||
});
|
||||
const logs = flatMap(data, (app, index) =>
|
||||
flatMap(app.Pods, (pod) => formatLogs(pod.Logs).map((line) => ({ ...line, appColor: colors[index % colors.length], appName: pod.Pod.Name })))
|
||||
);
|
||||
this.stackLogs = logs;
|
||||
} catch (err) {
|
||||
this.stopRepeater();
|
||||
|
@ -90,7 +82,8 @@ class KubernetesStackLogsController {
|
|||
}
|
||||
|
||||
downloadLogs() {
|
||||
const data = new this.Blob([(this.dataLogs = _.reduce(this.stackLogs, (acc, log) => acc + '\n' + log.AppName + ' ' + log.Line, ''))]);
|
||||
const logsAsString = concatLogsToString(this.state.filteredLogs, (line) => `${line.appName} ${line.line}`);
|
||||
const data = new this.Blob([logsAsString]);
|
||||
this.FileSaver.saveAs(data, this.state.transition.name + '_logs.txt');
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue