diff --git a/config/logger.ts b/config/logger.ts index a0d1663..ece6c76 100644 --- a/config/logger.ts +++ b/config/logger.ts @@ -1,16 +1,10 @@ import { winston } from "@strapi/logger"; +import { formatLogLine } from "../src/logging/format"; export default { transports: [ new winston.transports.Console({ - format: winston.format.combine( - winston.format.printf(({ timestamp, level, message, ...rest }) => { - let restString = JSON.stringify(rest, undefined, 2); - restString = restString === "{}" ? "" : restString; - - return `${timestamp}Z ${level}: ${message} ${restString}`; - }) - ) + format: winston.format.combine(winston.format.printf(formatLogLine)) }) ] }; diff --git a/src/logging/format.ts b/src/logging/format.ts new file mode 100644 index 0000000..693645a --- /dev/null +++ b/src/logging/format.ts @@ -0,0 +1,14 @@ +/** 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: `Z : `. */ +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}`; +};