Some checks failed
Deploy / deploy (push) Has been cancelled
Full-stack web application for Telegram management - Frontend: Vue 3 + Vben Admin - Backend: NestJS - Features: User management, group broadcast, statistics 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
49 lines
1.3 KiB
JavaScript
49 lines
1.3 KiB
JavaScript
import winston from 'winston';
|
|
import { config } from '../config/index.js';
|
|
|
|
const { combine, timestamp, json, printf, colorize } = winston.format;
|
|
|
|
// Custom format for console output
|
|
const consoleFormat = printf(({ level, message, timestamp, ...meta }) => {
|
|
const metaStr = Object.keys(meta).length ? ` ${JSON.stringify(meta)}` : '';
|
|
return `${timestamp} [${level}]: ${message}${metaStr}`;
|
|
});
|
|
|
|
// Create logger
|
|
export const logger = winston.createLogger({
|
|
level: config.logging.level,
|
|
format: combine(
|
|
timestamp(),
|
|
json()
|
|
),
|
|
transports: [
|
|
// Console transport
|
|
new winston.transports.Console({
|
|
format: combine(
|
|
colorize(),
|
|
timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }),
|
|
consoleFormat
|
|
)
|
|
}),
|
|
// File transport
|
|
new winston.transports.File({
|
|
filename: config.logging.file,
|
|
format: combine(
|
|
timestamp(),
|
|
json()
|
|
)
|
|
})
|
|
]
|
|
});
|
|
|
|
// Add error file transport in production
|
|
if (config.env === 'production') {
|
|
logger.add(new winston.transports.File({
|
|
filename: 'logs/error.log',
|
|
level: 'error',
|
|
format: combine(
|
|
timestamp(),
|
|
json()
|
|
)
|
|
}));
|
|
} |