47 lines
1.1 KiB
JavaScript
47 lines
1.1 KiB
JavaScript
const fs = require('fs');
|
|
const winston = require('winston');
|
|
|
|
// Create a logs directory if it doesn't exist
|
|
if (!fs.existsSync('logs')) {
|
|
fs.mkdirSync('logs');
|
|
}
|
|
|
|
// Define custom log levels
|
|
const customLevels = {
|
|
levels: {
|
|
error: 0,
|
|
warn: 1,
|
|
info: 2
|
|
},
|
|
colors: {
|
|
error: 'bold white redBG',
|
|
warn: 'bold red',
|
|
info: 'yellow'
|
|
},
|
|
};
|
|
|
|
// Add colors to winston
|
|
winston.addColors(customLevels.colors);
|
|
|
|
// Configure winston logger
|
|
const logger = winston.createLogger({
|
|
levels: customLevels.levels,
|
|
format: winston.format.combine(
|
|
winston.format.colorize(),
|
|
winston.format.timestamp(),
|
|
winston.format.printf(({ timestamp, level, message }) => {
|
|
return `${timestamp} ${level}: ${message}`;
|
|
})
|
|
),
|
|
transports: [
|
|
new winston.transports.Console(),
|
|
new winston.transports.File({ filename: 'logs/app.log' })
|
|
]
|
|
});
|
|
|
|
const initializeLogging = () => {
|
|
logger.info('Logging system initialized');
|
|
};
|
|
|
|
module.exports = { logger, initializeLogging };
|