I have a MERN app -- React frontend, Express/Mongoose backend -- that works fine locally. I deployed the backend to Heroku, the frontend to Surge and Winston no longer functions correctly. That is: it is not writing the log files at all, although it does so perfectly locally (localhost).
The Node version on Heroku is 8.11.4, whereas locally (MacOS) it's 10.8.0. And Heroku is being called through https rather than my localhost, which is running http. Those are the only differences I see.
I tried specifying __dirname
, tried remove a folder reference (that is, putting the files inside a directory logs
, but no log files are being written anywhere.
My logger module is the following
const {createLogger, format, transports} = require('winston');
const {combine, timestamp, align, colorize, printf} = format;
const path = require('path')
const myFormat = printf(info => {
return `${info.timestamp} [${info.level}: ${info.message}]`;
});
const logger = createLogger({
level: 'debug',
format: combine(
colorize(),
timestamp(),
align(),
myFormat
),
transports: [
new transports.File({maxsize: 500000, filename: path.join(__dirname,'logs/error.log'), level: 'error'}),
new transports.File({maxsize: 500000, filename: path.join(__dirname,'logs/combined.log')})
]
})
module.exports = logger
Again, the frustrating thing is it all works perfectly locally. Thanks for any help in tracking this down!
Heroku hasn't local storage. Use mail transport to get errors from a server. Or You can use Heroku services for monitoring your app. Like: Addons-Loggers