mirror of
https://github.com/fosrl/pangolin.git
synced 2025-06-24 14:18:55 +02:00
share links
This commit is contained in:
parent
72dc02ff2e
commit
845d65ad33
31 changed files with 1281 additions and 212 deletions
|
@ -4,82 +4,53 @@ import * as winston from "winston";
|
|||
import path from "path";
|
||||
|
||||
const hformat = winston.format.printf(
|
||||
({ level, label, message, timestamp, ...metadata }) => {
|
||||
let msg = `${timestamp} [${level}]${label ? `[${label}]` : ""}: ${message} `;
|
||||
({ level, label, message, timestamp, stack, ...metadata }) => {
|
||||
let msg = `${timestamp} [${level}]${label ? `[${label}]` : ""}: ${message}`;
|
||||
if (stack) {
|
||||
msg += `\nStack: ${stack}`;
|
||||
}
|
||||
if (Object.keys(metadata).length > 0) {
|
||||
msg += JSON.stringify(metadata);
|
||||
msg += ` ${JSON.stringify(metadata)}`;
|
||||
}
|
||||
return msg;
|
||||
},
|
||||
}
|
||||
);
|
||||
|
||||
const transports: any = [
|
||||
new winston.transports.Console({
|
||||
format: winston.format.combine(
|
||||
winston.format.errors({ stack: true }),
|
||||
winston.format.colorize(),
|
||||
winston.format.splat(),
|
||||
winston.format.timestamp(),
|
||||
hformat,
|
||||
),
|
||||
}),
|
||||
];
|
||||
const transports: any = [new winston.transports.Console({})];
|
||||
|
||||
if (config.app.save_logs) {
|
||||
transports.push(
|
||||
new winston.transports.DailyRotateFile({
|
||||
filename: path.join(
|
||||
APP_PATH,
|
||||
"logs",
|
||||
"pangolin-%DATE%.log",
|
||||
),
|
||||
filename: path.join(APP_PATH, "logs", "pangolin-%DATE%.log"),
|
||||
datePattern: "YYYY-MM-DD",
|
||||
zippedArchive: true,
|
||||
maxSize: "20m",
|
||||
maxFiles: "7d",
|
||||
createSymlink: true,
|
||||
symlinkName: "pangolin.log",
|
||||
}),
|
||||
);
|
||||
transports.push(
|
||||
new winston.transports.DailyRotateFile({
|
||||
filename: path.join(
|
||||
APP_PATH,
|
||||
"logs",
|
||||
".machinelogs-%DATE%.json",
|
||||
),
|
||||
datePattern: "YYYY-MM-DD",
|
||||
zippedArchive: true,
|
||||
maxSize: "20m",
|
||||
maxFiles: "1d",
|
||||
createSymlink: true,
|
||||
symlinkName: ".machinelogs.json",
|
||||
format: winston.format.combine(
|
||||
winston.format.timestamp(),
|
||||
winston.format.splat(),
|
||||
winston.format.json(),
|
||||
),
|
||||
}),
|
||||
symlinkName: "pangolin.log"
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
const logger = winston.createLogger({
|
||||
level: config.app.log_level.toLowerCase(),
|
||||
format: winston.format.combine(
|
||||
winston.format.errors({ stack: true }),
|
||||
winston.format.colorize(),
|
||||
winston.format.splat(),
|
||||
winston.format.timestamp(),
|
||||
hformat,
|
||||
hformat
|
||||
),
|
||||
transports,
|
||||
transports
|
||||
});
|
||||
|
||||
// process.on("uncaughtException", (error) => {
|
||||
// logger.error("Uncaught Exception:", { error, stack: error.stack });
|
||||
// process.exit(1);
|
||||
// });
|
||||
//
|
||||
// process.on("unhandledRejection", (reason, _) => {
|
||||
// logger.error("Unhandled Rejection:", { reason });
|
||||
// });
|
||||
process.on("uncaughtException", (error) => {
|
||||
logger.error("Uncaught Exception:", { error, stack: error.stack });
|
||||
process.exit(1);
|
||||
});
|
||||
|
||||
process.on("unhandledRejection", (reason, _) => {
|
||||
logger.error("Unhandled Rejection:", { reason });
|
||||
});
|
||||
|
||||
export default logger;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue