Skip to content

Commit 0829ff1

Browse files
committed
backend-common: include extra fields on dev log formatter
1 parent 57deaf0 commit 0829ff1

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

.changeset/mighty-plums-wave.md

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
'@backstage/backend-common': patch
3+
---
4+
5+
Tweaked development log formatter to include extra fields at the end of each log line

packages/backend-common/src/logging/formats.ts

+7-3
Original file line numberDiff line numberDiff line change
@@ -17,19 +17,23 @@ import * as winston from 'winston';
1717
import { TransformableInfo } from 'logform';
1818

1919
const coloredTemplate = (info: TransformableInfo) => {
20-
const { timestamp, level, message, plugin, service } = info;
20+
const { timestamp, level, message, plugin, service, ...fields } = info;
2121
const colorizer = winston.format.colorize();
2222
const prefix = plugin || service;
2323
const timestampColor = colorizer.colorize('timestamp', timestamp);
2424
const prefixColor = colorizer.colorize('prefix', prefix);
2525

26-
return `${timestampColor} ${prefixColor} ${level} ${message}`;
26+
const extraFields = Object.entries(fields)
27+
.map(([key, value]) => `${colorizer.colorize('field', `${key}`)}=${value}`)
28+
.join(' ');
29+
30+
return `${timestampColor} ${prefixColor} ${level} ${message} ${extraFields}`;
2731
};
2832

2933
export const coloredFormat = winston.format.combine(
3034
winston.format.timestamp(),
3135
winston.format.colorize({
32-
colors: { timestamp: 'dim', prefix: 'blue' },
36+
colors: { timestamp: 'dim', prefix: 'blue', field: 'cyan' },
3337
}),
3438
winston.format.printf(coloredTemplate),
3539
);

0 commit comments

Comments
 (0)