Node => 16.14.0
Strapi => 4.4.3
Typescript => 4.8.3
OS => Windows 10
Hi everyone, I’ve successfully migrated my Strapi project to typescript recently. I’ve also configured Winston loggers in config/logger.ts
(I’ve added the implementation in the next message)
When I run yarn develop
, the compilation of Strapi is done successfully and a folder gets created in the dist
folder called logs
with two files named http.log
and error.log
.
So here’s the thing: when I change the server code and wait for the reload, the following error is printed in terminal:
This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). The promise rejected with the reason:
Error: ENOTEMPTY: directory not empty, rmdir 'D:\Repositories\Gitlab\lumos-cms\backend\dist\logs'
So I need to stop Strapi and start it again.
Any thoughts on this?
/*config/logger.ts*/
import { winston, formats } from "@strapi/logger";
import path from "path";
const { prettyPrint, levelFilter } = formats;
export default {
transports: [
new winston.transports.Console({
level: "http",
silent: process.env.RUN_CONSOLE_LOGGER_IN_SILENT_MODE === "true",
format: winston.format.combine(
levelFilter("http"),
prettyPrint({ timestamps: "YYYY-MM-DD hh:mm:ss.SSS" })
),
}),
new winston.transports.File({
filename: path.join(__dirname, "../logs/http.log"),
level: "http",
silent: process.env.RUN_HTTP_LOGGER_IN_SILENT_MODE === "true",
format: winston.format.combine(
winston.format.uncolorize(),
winston.format((info) => {
try {
// Only log messages containing status code greater than or equal to 400
if (parseInt(info.message.slice(-3)) < 400) return false;
return info;
} catch (error) {
console.log(error, "error happened while logging");
return info;
}
})(),
levelFilter("http"),
prettyPrint({ timestamps: "YYYY-MM-DD hh:mm:ss.SSS" }),
winston.format.uncolorize()
),
}),
new winston.transports.File({
filename: path.join(__dirname, "../logs/error.log"),
level: "error",
silent: process.env.RUN_ERROR_LOGGER_IN_SILENT_MODE === "true",
format: winston.format.combine(
levelFilter("error"),
prettyPrint({ timestamps: "YYYY-MM-DD hh:mm:ss.SSS" }),
winston.format.uncolorize(),
winston.format.json()
),
}),
],
};
I’ve tried running it as administrator but didn’t help.