Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pm2 changing log file location

I have couple of questions regarding pm2

  • How can I change the location of server-error-0.log and server-out-0.log files location from c:\users\user\.pm2\logs to other drive, due to restriction in server's c drive access.
  • Can I log the error and info in database instead of a log file? Do I need to write a separate module for that or is there any way to achieve this?
like image 300
Jeet Avatar asked Aug 30 '17 06:08

Jeet


People also ask

Where do pm2 logs go?

Log files are located in the folder $HOME/. pm2/logs .

Where is pm2 config file stored?

The default configuration file is ecosystem. core3. config. js , and is located in the root folder of lisk-service : It contains a configuration to connect to a local Lisk Core node.

What are pm2 logs?

pm2 has two types of log files for every app that it runs, an error log file and an out log file. The error logs are saved to $HOME/.pm2/logs/XXX-error.log or ~/.pm2/logs/XXX-error.log. While the out logs are saved to $HOME/.

Where is node JS log file?

Answer. Note: Node. js can also records logs directly into /var/www/vhosts/system/example.com/logs/ directory, but this functionality is a part of Passenger Enterprise which is not included into the free edition that is provided by Plesk.


1 Answers

How can I change the location of ...log file location?

To change pm2's log file location, there are 2 solutions: define log path as parameter when pm2 command is executed (-l, -o, -e), or start pm2 from a configuration file.

For the parameter solution, here is an example:

pm2 start app.js -o ./out.log -e ./err.log

If you don't want to define log path every time when pm2 is executed, you can generate a configuration file, define error_file and out_file, and start pm2 from that:

  1. Generate a configuration file: pm2 ecosystem simple. This would generate a file ecosystem.config.js, with following content:

    module.exports = {
      apps : [{
        name   : "app1",
        script : "./app.js"
      }]
    }
    
  2. Define error_file (for error log) and out_file (for info log) in the file, such as:

    module.exports = {
      apps : [{
        name   : "app1",
        script : "./app.js",
        error_file : "./err.log",
        out_file : "./out.log"
      }]
    }
    
  3. Delete existing processes in pm2:

    pm2 delete <pid>
    

    You can get pid by doing:

    pm2 status
    
  4. Start the process from the configuration file:

    pm2 start ecosystem.config.js
    

In this way, the logs are saved to ./err.log and ./out.log.

Please refer to the document for detail information.

Can I log the error and info in database instead of a log file?

I didn't find any resources in official document. It seems you need to write code and save log to database yourself.

like image 96
shaochuancs Avatar answered Oct 07 '22 18:10

shaochuancs