This commit is contained in:
Lee
2024-01-01 17:04:19 +00:00
parent 3750a00017
commit a3dbd9e689
11 changed files with 476 additions and 104 deletions

31
src/utils/logger.ts Normal file
View File

@ -0,0 +1,31 @@
import Winston, { format } from "winston";
const { colorize, timestamp, printf } = format;
interface LogInfo {
level: string;
message: string;
label?: string;
timestamp?: string;
}
const customFormat = format.combine(
timestamp({ format: "YY-MM-DD HH:MM:SS" }),
printf((info: LogInfo) => {
return `[${info.timestamp}] ${info.level}: ${info.message}`;
})
);
/**
* The global logger instance.
*/
export const logger = Winston.createLogger({
transports: [
new Winston.transports.Console({
format: Winston.format.combine(colorize(), customFormat),
}),
new Winston.transports.File({
filename: `data/logs/${new Date().toISOString().slice(0, 10)}.log`,
format: Winston.format.combine(customFormat),
}),
],
});

8
src/utils/timeUtils.ts Normal file
View File

@ -0,0 +1,8 @@
/**
* Gets the current date as YYYY-MM-DD.
*
* @returns the date
*/
export function getFormattedDate() {
return new Date().toISOString().slice(0, 10);
}