mirror of
https://github.com/MasterAcnolo/Freedom-Loader.git
synced 2026-09-27 20:11:15 +02:00
refactor: enhance log format by adding color when app is run in an IDE or a Terminal
This commit is contained in:
committed by
MasterAcnolo
parent
df0952c231
commit
73aa81673b
@@ -22,6 +22,31 @@ const logFormat = format.combine(
|
||||
format.printf(({ timestamp, level, message }) => `${timestamp} | ${level.toUpperCase()} | ${message}`)
|
||||
);
|
||||
|
||||
/**
|
||||
* Format used by the saved file
|
||||
* @type {Format}
|
||||
*/
|
||||
const fileFormat = format.combine(
|
||||
format.timestamp({format: "YYYY-MM-DD HH:mm:ss"}),
|
||||
format.errors({stack: true}), // Capture la stack trace complète des erreurs
|
||||
format.printf(({timestamp, level, message, stack}) => {
|
||||
return `${timestamp} | ${level.toUpperCase()} | ${stack || message}`;
|
||||
})
|
||||
);
|
||||
|
||||
/**
|
||||
* Formated used by the IDE/Console
|
||||
* @type {Format}
|
||||
*/
|
||||
const consoleFormat = format.combine(
|
||||
format.colorize({all: true}),
|
||||
format.timestamp({format: "HH:mm:ss"}),
|
||||
format.errors({stack: true}),
|
||||
format.printf(({timestamp, level, message, stack}) => {
|
||||
return `[${timestamp}] ${level}: ${stack || message}`;
|
||||
})
|
||||
);
|
||||
|
||||
/**
|
||||
* Logger Instance with differents types
|
||||
* - info
|
||||
@@ -33,7 +58,6 @@ const logFormat = format.combine(
|
||||
*/
|
||||
const logger = createLogger({
|
||||
level: "info",
|
||||
format: logFormat,
|
||||
transports: [
|
||||
new DailyRotateFile({
|
||||
dirname: logDir,
|
||||
@@ -41,11 +65,11 @@ const logger = createLogger({
|
||||
datePattern: "YYYY-MM-DD",
|
||||
zippedArchive: false,
|
||||
maxFiles: "7d",
|
||||
format: logFormat,
|
||||
format: fileFormat,
|
||||
options: { flags: "a" },
|
||||
}),
|
||||
new transports.Console({
|
||||
format: logFormat,
|
||||
format: consoleFormat,
|
||||
}),
|
||||
],
|
||||
});
|
||||
@@ -57,7 +81,7 @@ function logSessionStart(logDir, downloadPath) {
|
||||
logger.info(`--- Starting session: ${new Date().toISOString()} ---`);
|
||||
logger.info("============================================================")
|
||||
logger.info(`Application Version: ${config.version}`)
|
||||
logSystemInfo(logger, logDir, downloadPath)
|
||||
if (typeof logSystemInfo === 'function') logSystemInfo(logger, logDir, downloadPath);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
Reference in New Issue
Block a user