26 lines
711 B
JavaScript
26 lines
711 B
JavaScript
const winston = require("winston");
|
|
|
|
const prettyFormat = winston.format.printf(({ timestamp, level, message, error, ...meta }) => {
|
|
const logObject = {
|
|
timestamp,
|
|
level,
|
|
message,
|
|
...(Object.keys(meta).length ? { meta } : {}),
|
|
};
|
|
|
|
return JSON.stringify(logObject, null, 2);
|
|
});
|
|
|
|
const logger = winston.createLogger({
|
|
level: "info",
|
|
format: winston.format.combine(
|
|
winston.format.errors({ stack: true }),
|
|
winston.format.timestamp({ format: "YYYY-MM-DD HH:mm:ss" }),
|
|
prettyFormat),
|
|
transports: [
|
|
new winston.transports.Console(),
|
|
new winston.transports.File({ filename: "./Logs/error.log", level: "error" }),
|
|
],
|
|
});
|
|
|
|
module.exports = logger; |