SIU_Dran_net/Server/utils/logger.js

28 lines
631 B
JavaScript
Raw Normal View History

2024-06-03 04:59:59 +00:00
import { createLogger, format, transports } from 'winston';
import caller from 'caller';
const myFormat = format.printf(info => {
2024-06-03 14:13:02 +00:00
const file = caller();
2024-06-03 04:59:59 +00:00
return `[${info.timestamp}] [${info.level}] ${info.message}`;
});
const logger = createLogger({
format: format.combine(
2024-06-03 14:13:02 +00:00
format.colorize(),
2024-06-03 04:59:59 +00:00
format.timestamp(),
myFormat
),
transports: [
new transports.File({
maxsize: 5120000,
maxFiles: 5,
filename: `./logs/log-api.log`
}),
new transports.Console({
level: 'debug'
})
]
});
export default logger;