How to get logging working with pm2 and Heroku
Asked Answered
L

2

12

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).

Legitimist answered 20/8, 2015 at 17:23 Comment(0)
R
16

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
Rosyrot answered 10/9, 2015 at 1:49 Comment(3)
Thx! Installing pm2 globally helped me run pm2 on heroku without it immediately crashingOverhang
pm2-runtime app.js -i max instead pm2 start app.js && pm2 logs all?Feeler
This is confusing.. Once I used pm2-logrotate all I see is the realtime logs. My historic logs are always just loading...Forgiven
D
3

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

Daedalus answered 25/8, 2015 at 13:51 Comment(2)
Unfortunately, this guide doesn't tell the most important info — pm2 must be installed globally and for a proper logging pm2-logrotate is required. The bottom line, Liko's answer solves the issue, while pm2's documentation doesn't!Reichert
@Reichert wow really , thank God for your answer, i was about to try PM2 docsArgosy

© 2022 - 2024 — McMap. All rights reserved.