Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get logging working with pm2 and Heroku

Tags:

heroku

pm2

Is there a way to tell pm2 to leave stderr and stdout alone (as opposed to writing to files)?

I'm using pm2 on Heroku using this gist as my model. Everything seems to work perfectly except that I've lost any ability to log from within my app. They don't show up in the Heroku logs and the files that pm2 creates aren't accessible to me on Heroku's file system (or I can't find them).

like image 253
Boon Avatar asked Aug 20 '15 17:08

Boon


2 Answers

In your package.json:

"scripts": {
  "preinstall": "npm i -g pm2 && pm2 install pm2-logrotate"
}

In your Procfile:

web: pm2 start app.js && pm2 logs all
like image 157
Liko Avatar answered Sep 28 '22 04:09

Liko


We just created the official PM2 documentation, here is how to integrate PM2 with Heroku while printing the logs:

http://pm2.keymetrics.io/docs/usage/use-pm2-with-cloud-providers/#heroku-google-app-engine-azure

Alex

like image 39
Unitech Avatar answered Sep 28 '22 04:09

Unitech