| 1234567891011121314151617181920 |
- import winston from 'winston'
- import { ProductionLogger, logger as productionLogger } from './ProductionLogger.js'
- const { combine, timestamp, printf, colorize } = winston.format
- const logFormat = printf(({ level, message, timestamp }) => {
- return `${timestamp} [${level}] ${message}`
- })
- // 保持向后兼容的 Winston logger
- const winstonLogger = winston.createLogger({
- level: process.env.LOG_LEVEL || 'info',
- format: combine(timestamp(), logFormat),
- transports: [
- new winston.transports.Console({
- format: combine(colorize(), timestamp(), logFormat),
- }),
- ],
- })
- // 生产环境使用新的 ProductionLogger,开发环境使用 Winston
- export const logger = process.env.NODE_ENV === 'production' ? productionLogger : winstonLogger
- // 导出新的生产日志器供直接使用
- export { ProductionLogger, productionLogger }
|