Skip to content

Commit

Permalink
fix: fixes wrong timestamp format
Browse files Browse the repository at this point in the history
closes #794
  • Loading branch information
Disane87 committed May 29, 2024
1 parent 7e9ab8e commit ed2e2ef
Showing 1 changed file with 47 additions and 33 deletions.
80 changes: 47 additions & 33 deletions src/helpers/logger.helper.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,51 @@
import * as path from 'path';
import * as path from "path";
import winston, { format } from "winston";

export const createLogger = (
logLevel: string,
logPath: string,
context = `DocuDigger`,
) => {
const logFormat = format.combine(
format.label({ label: context }),
format.timestamp({
format: `YYYY-MM-DD HH:MM:ss`,
}),
format.prettyPrint(),
format.colorize(),
format.align(),
// eslint-disable-next-line @typescript-eslint/no-explicit-any
format.printf((info: any) => {
return `[${info.level}] [${info.timestamp}] [${info.label}]: ${info.message}`;
}),
);

export const createLogger = (logLevel: string, logPath: string, context = `DocuDigger`) => {
const logFormat = format.combine(
format.label({ label: context }),
format.timestamp({
format: `YYYY-MM-DD HH-MM:ss`
}),
format.prettyPrint(),
format.colorize(),
format.align(),
// eslint-disable-next-line @typescript-eslint/no-explicit-any
format.printf((info: any) => {
return `[${info.level}] [${info.timestamp}] [${info.label}]: ${info.message}`;
})
);
return winston.createLogger({
level: logLevel.toString(),
format: logFormat,

return winston.createLogger({
level: logLevel.toString(),
format: logFormat,

rejectionHandlers: [
new winston.transports.File({ filename: `rejections.log` })
],
exceptionHandlers: [
new winston.transports.File({ filename: `exceptions.log` })
],
transports: [
new winston.transports.Console({ handleExceptions: true, handleRejections: true }),
new winston.transports.File({ filename: path.join(logPath, `error.log`).normalize(), level: `error` }),
new winston.transports.File({ filename: path.join(logPath, `verbose.log`).normalize(), level: `verbose` }),
new winston.transports.File({ filename: path.join(logPath, `combined.log`).normalize() })
]
});
};
rejectionHandlers: [
new winston.transports.File({ filename: `rejections.log` }),
],
exceptionHandlers: [
new winston.transports.File({ filename: `exceptions.log` }),
],
transports: [
new winston.transports.Console({
handleExceptions: true,
handleRejections: true,
}),
new winston.transports.File({
filename: path.join(logPath, `error.log`).normalize(),
level: `error`,
}),
new winston.transports.File({
filename: path.join(logPath, `verbose.log`).normalize(),
level: `verbose`,
}),
new winston.transports.File({
filename: path.join(logPath, `combined.log`).normalize(),
}),
],
});
};

0 comments on commit ed2e2ef

Please sign in to comment.