|
|
@ -1,6 +1,6 @@
|
|
|
|
/* eslint-disable no-console */
|
|
|
|
/* eslint-disable no-console */
|
|
|
|
import { join } from "path";
|
|
|
|
import { join } from "path";
|
|
|
|
import { format as utilFormat } from "node:util"
|
|
|
|
import { format as utilFormat } from "node:util";
|
|
|
|
|
|
|
|
|
|
|
|
import winston from "winston";
|
|
|
|
import winston from "winston";
|
|
|
|
|
|
|
|
|
|
|
@ -15,10 +15,10 @@ function init() {
|
|
|
|
transform: (info, opts) => {
|
|
|
|
transform: (info, opts) => {
|
|
|
|
// combine message and args if any
|
|
|
|
// combine message and args if any
|
|
|
|
// eslint-disable-next-line no-param-reassign
|
|
|
|
// eslint-disable-next-line no-param-reassign
|
|
|
|
info.message = utilFormat(info.message, ...info[Symbol.for('splat')] || []);
|
|
|
|
info.message = utilFormat(info.message, ...(info[Symbol.for("splat")] || []));
|
|
|
|
return info;
|
|
|
|
return info;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
function messageFormatter(logInfo) {
|
|
|
|
function messageFormatter(logInfo) {
|
|
|
@ -33,10 +33,10 @@ function init() {
|
|
|
|
return `[${logInfo.timestamp}] ${logInfo.level}: ${logInfo.stack}`;
|
|
|
|
return `[${logInfo.timestamp}] ${logInfo.level}: ${logInfo.stack}`;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return `[${logInfo.timestamp}] ${logInfo.level}: ${logInfo.message}`;
|
|
|
|
return `[${logInfo.timestamp}] ${logInfo.level}: ${logInfo.message}`;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
winstonLogger = winston.createLogger({
|
|
|
|
winstonLogger = winston.createLogger({
|
|
|
|
level: process.env.LOG_LEVEL || 'info',
|
|
|
|
level: process.env.LOG_LEVEL || "info",
|
|
|
|
transports: [
|
|
|
|
transports: [
|
|
|
|
new winston.transports.Console({
|
|
|
|
new winston.transports.Console({
|
|
|
|
format: winston.format.combine(
|
|
|
|
format: winston.format.combine(
|
|
|
@ -47,7 +47,7 @@ function init() {
|
|
|
|
winston.format.printf(messageFormatter)
|
|
|
|
winston.format.printf(messageFormatter)
|
|
|
|
),
|
|
|
|
),
|
|
|
|
handleExceptions: true,
|
|
|
|
handleExceptions: true,
|
|
|
|
handleRejections: true
|
|
|
|
handleRejections: true,
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
|
|
|
|
|
|
|
|
new winston.transports.File({
|
|
|
|
new winston.transports.File({
|
|
|
@ -59,30 +59,36 @@ function init() {
|
|
|
|
),
|
|
|
|
),
|
|
|
|
filename: `${configPath}/logs/homepage.log`,
|
|
|
|
filename: `${configPath}/logs/homepage.log`,
|
|
|
|
handleExceptions: true,
|
|
|
|
handleExceptions: true,
|
|
|
|
handleRejections: true
|
|
|
|
handleRejections: true,
|
|
|
|
}),
|
|
|
|
}),
|
|
|
|
]
|
|
|
|
],
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
// patch the console log mechanism to use our logger
|
|
|
|
// patch the console log mechanism to use our logger
|
|
|
|
const consoleMethods = ['log', 'debug', 'info', 'warn', 'error']
|
|
|
|
const consoleMethods = ["log", "debug", "info", "warn", "error"];
|
|
|
|
consoleMethods.forEach(method => {
|
|
|
|
consoleMethods.forEach((method) => {
|
|
|
|
// workaround for https://github.com/winstonjs/winston/issues/1591
|
|
|
|
// workaround for https://github.com/winstonjs/winston/issues/1591
|
|
|
|
switch (method) {
|
|
|
|
switch (method) {
|
|
|
|
case 'log':
|
|
|
|
case "log":
|
|
|
|
console[method] = winstonLogger.info.bind(winstonLogger);
|
|
|
|
console[method] = winstonLogger.info.bind(winstonLogger);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
default:
|
|
|
|
console[method] = winstonLogger[method].bind(winstonLogger);
|
|
|
|
console[method] = winstonLogger[method].bind(winstonLogger);
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
})
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
const loggers = {};
|
|
|
|
|
|
|
|
|
|
|
|
export default function createLogger(label) {
|
|
|
|
export default function createLogger(label) {
|
|
|
|
if (!winstonLogger) {
|
|
|
|
if (!winstonLogger) {
|
|
|
|
init();
|
|
|
|
init();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return winstonLogger.child({ label });
|
|
|
|
if (!loggers[label]) {
|
|
|
|
|
|
|
|
loggers[label] = winstonLogger.child({ label });
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return loggers[label];
|
|
|
|
}
|
|
|
|
}
|