backend/utils/logger.js

27 lines
958 B
JavaScript
Raw Normal View History

2023-03-03 16:44:40 +00:00
const winston = require('winston')
const { Logtail } = require("@logtail/node")
const { LogtailTransport } = require("@logtail/winston")
2023-07-07 19:58:03 +00:00
const logtail = new Logtail(process.env.LOGTAIL)
2023-03-03 16:44:40 +00:00
const logger = winston.createLogger({
format: winston.format.json(),
transports: [
new winston.transports.Console({
format:winston.format.combine(
winston.format.timestamp({format: 'MMM-DD-YYYY HH:mm:ss'}),
2023-03-25 12:27:41 +00:00
winston.format.printf(info => `${[info.timestamp]}: ${info.message}`),
2023-03-03 16:44:40 +00:00
)}),
new winston.transports.File({
filename: 'logs/client.log',
format:winston.format.combine(
winston.format.timestamp({format: 'MMM-DD-YYYY HH:mm:ss'}),
winston.format.printf(info => `${[info.timestamp]}: ${info.message}`),
)}),
new LogtailTransport(logtail, {
level: 'error'
})
2023-03-03 16:44:40 +00:00
],
});
module.exports = logger