I want to add new level critical
for log of winston-daily-rotate-file
.
I declare critical: LeveledLogMethod;
in class Logger extends NodeJSStream.Transform
of index.d.ts
of winston/index.d.ts
.
In logger.ts of my application, I create a function critical and return FLLogger.getInstance().logger.critical(fullMessage, error);
in it.
However, I receive an message that FLLogger.getInstance(...).logger.critical is not a function.
.
Here is my code in logger.ts
public static critical(fileName: string, methodName: string, message: string, errorCode: string, error?: any) {
const fullMessage = `[CODE: ${errorCode}] [FILE: ${fileName}] [METHOD: ${methodName}] [Host IP: ${this.getHostIP()}] ${message}: `;
FLLogger.getInstance().logger.critical(fullMessage, error);
}
public static init() {
FLLogger.getInstance().logger = createLogger({
format: format.combine(
format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss.SSS' }), // Customize timestamp format
format.errors({ stack: true }), // Include errors if any
format.prettyPrint(),
format.printf((info) => `[${info.timestamp}] [${info.level.toUpperCase()}] ${info.message}.`,
),
),
transports: [
new transports.Console(),
new transports.DailyRotateFile({
dirname: `/${Constants.LOG_FOLDER_NAME}`,
filename: 'app-%DATE%-critical.log',
datePattern: 'YYYY-MM-DD',
zippedArchive: true, // archive log files for backup
maxSize: '10m', // Log file size
maxFiles: '30d', // Delete log file in 30 days
level: 'critical',
}),
],
});
}
How to fix it? Does I miss something and please explain me why?