29 lines
792 B
TypeScript
29 lines
792 B
TypeScript
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 }),
|
||
|
|
winston.format.json()
|
||
|
|
),
|
||
|
|
defaultMeta: { service: 'teleuploader' },
|
||
|
|
transports: [
|
||
|
|
// Write all logs including error logs to file
|
||
|
|
new winston.transports.File({ filename: 'logs/error.log', level: 'error' }),
|
||
|
|
new winston.transports.File({ filename: 'logs/combined.log' })
|
||
|
|
]
|
||
|
|
});
|
||
|
|
|
||
|
|
// If not production, also log to console
|
||
|
|
if (process.env.NODE_ENV !== 'production') {
|
||
|
|
logger.add(new winston.transports.Console({
|
||
|
|
format: winston.format.combine(
|
||
|
|
winston.format.colorize(),
|
||
|
|
winston.format.simple()
|
||
|
|
)
|
||
|
|
}));
|
||
|
|
}
|
||
|
|
|
||
|
|
export default logger;
|