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
15 lines
586 B
TypeScript
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}`;
|
|
};
|