Files
cms/src/logging/format.ts
T
libretech 7fd4aeff17 refactor(logging): move the console line format into src/logging/format.ts
The printf template of config/logger.ts becomes formatLogLine, with the same
logic, so it can be unit tested without winston.

No behaviour change.

Refs libretech/mp#71
2026-10-08 22:10:28 +02:00

15 lines
586 B
TypeScript

/** What winston hands a printf template (logform's TransformableInfo); Strapi's default format has added `timestamp`. */
export type LogInfo = {
level: string;
message: unknown;
[key: string | symbol]: unknown;
};
/** One console line: `<timestamp>Z <level>: <message> <all other fields as indented JSON, if any>`. */
export const formatLogLine = ({ timestamp, level, message, ...rest }: LogInfo): string => {
let restString = JSON.stringify(rest, undefined, 2);
restString = restString === "{}" ? "" : restString;
return `${timestamp}Z ${level}: ${message} ${restString}`;
};