2026-05-18 06:53:33 +07:00
|
|
|
import winston from 'winston';
|
|
|
|
|
|
|
|
|
|
const logger = winston.createLogger({
|
|
|
|
|
level: process.env.LOG_LEVEL || 'info',
|
|
|
|
|
format: winston.format.combine(
|
|
|
|
|
winston.format.timestamp(),
|
|
|
|
|
winston.format.errors({ stack: true }),
|
2026-05-18 07:29:01 +07:00
|
|
|
winston.format.json(),
|
2026-05-18 06:53:33 +07:00
|
|
|
),
|
|
|
|
|
defaultMeta: { service: 'teleuploader' },
|
|
|
|
|
transports: [
|
|
|
|
|
// Write all logs including error logs to file
|
|
|
|
|
new winston.transports.File({ filename: 'logs/error.log', level: 'error' }),
|
2026-05-18 07:29:01 +07:00
|
|
|
new winston.transports.File({ filename: 'logs/combined.log' }),
|
|
|
|
|
],
|
2026-05-18 06:53:33 +07:00
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// If not production, also log to console
|
|
|
|
|
if (process.env.NODE_ENV !== 'production') {
|
2026-05-18 07:29:01 +07:00
|
|
|
logger.add(
|
|
|
|
|
new winston.transports.Console({
|
|
|
|
|
format: winston.format.combine(winston.format.colorize(), winston.format.simple()),
|
|
|
|
|
}),
|
|
|
|
|
);
|
2026-05-18 06:53:33 +07:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export default logger;
|