I have couple of questions regarding pm2
- How can I change the location of
server-error-0.log
andserver-out-0.log
files location fromc:\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?
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:
If you don't want to define log path every time when pm2 is executed, you can generate a configuration file, define
error_file
andout_file
, and start pm2 from that:Generate a configuration file:
pm2 ecosystem simple
. This would generate a fileecosystem.config.js
, with following content:Define
error_file
(for error log) andout_file
(for info log) in the file, such as:Delete existing processes in pm2:
You can get pid by doing:
Start the process from the configuration file:
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.