Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make pm2 log to console

Tags:

node.js

pm2

I am running a node webserver using pm2. Since pm2 spawns another process and redirects stdout and stderr to files, I have to look somewhere else for the logs. Ideally, I would like to have the node process output to the same console window that I've run pm2 from. Otherwise, I would settle for pm2 run the node process with an active console window and have stdout and stderr of the node process write to that console window. How can this be achieved? I'm on a windows machine.

like image 643
Fragilerus Avatar asked Mar 18 '16 03:03

Fragilerus


People also ask

How do you show log pm2?

Application Logs Once an application is started with PM2 you can consult and manage logs easily. Log files are located in the folder $HOME/. pm2/logs .

Where are pm2 logs stored?

By default, all logs are saved into $HOME/. pm2/logs .

Can I console log from node module?

You can put console logs but just remember to restart the server. Hot reload does not detect changes in dist folders of libraries in node_modules.


2 Answers

I believe you can also see the stdout and stderr of a process that is running daemonized by the command pm2 logs or pm2 logs [app-name].

like image 144
Timothy Vann Avatar answered Sep 27 '22 20:09

Timothy Vann


you can easily achieve that by starting another terminal/console and run this command

 pm2 log 

logs everything to the terminal except console.log

 pm2 logs 

logs everything to the terminal and console.log

notice the 's' in the second command

like image 37
Chukwuemeka Maduekwe Avatar answered Sep 27 '22 21:09

Chukwuemeka Maduekwe