diff --git a/public/app/features/logs/components/panel/processing.ts b/public/app/features/logs/components/panel/processing.ts index b40577f1def..60e51ca91d4 100644 --- a/public/app/features/logs/components/panel/processing.ts +++ b/public/app/features/logs/components/panel/processing.ts @@ -1,3 +1,4 @@ +import ansicolor from 'ansicolor'; import Prism, { Grammar } from 'prismjs'; import { DataFrame, dateTimeFormat, Labels, LogLevel, LogRowModel, LogsSortOrder } from '@grafana/data'; @@ -132,9 +133,9 @@ export class LogListModel implements LogRowModel { return checkLogsSampled(this); } - getDisplayedFieldValue(fieldName: string): string { + getDisplayedFieldValue(fieldName: string, stripAnsi = false): string { if (fieldName === LOG_LINE_BODY_FIELD_NAME) { - return this.body; + return stripAnsi ? ansicolor.strip(this.body) : this.body; } let fieldValue = ''; if (this.labels[fieldName] != null) { @@ -155,8 +156,8 @@ export class LogListModel implements LogRowModel { updateCollapsedState(displayedFields: string[], container: HTMLDivElement | null) { const lineLength = displayedFields.length > 0 - ? displayedFields.map((field) => this.getDisplayedFieldValue(field)).join('').length - : this.raw.length; + ? displayedFields.map((field) => this.getDisplayedFieldValue(field, true)).join('').length + : this.entry.length; const collapsed = lineLength >= (this._virtualization?.getTruncationLength(container) ?? TRUNCATION_DEFAULT_LENGTH) ? true diff --git a/public/app/features/logs/components/panel/virtualization.ts b/public/app/features/logs/components/panel/virtualization.ts index e5edf24864a..2f9b6b6773a 100644 --- a/public/app/features/logs/components/panel/virtualization.ts +++ b/public/app/features/logs/components/panel/virtualization.ts @@ -193,7 +193,7 @@ export class LogLineVirtualization { levelWidth = Math.round(width); } for (const field of displayedFields) { - width = this.measureTextWidth(logs[i].getDisplayedFieldValue(field)); + width = this.measureTextWidth(logs[i].getDisplayedFieldValue(field, true)); fieldWidths[field] = !fieldWidths[field] || width > fieldWidths[field] ? Math.round(width) : fieldWidths[field]; } } @@ -288,7 +288,7 @@ export function getLogLineSize( textToMeasure += logs[index].displayLevel ?? ''; } for (const field of displayedFields) { - textToMeasure = logs[index].getDisplayedFieldValue(field) + textToMeasure; + textToMeasure = logs[index].getDisplayedFieldValue(field, true) + textToMeasure; } if (!displayedFields.length) { textToMeasure += ansicolor.strip(logs[index].body);