PM2 user defined Log, PID and other Log File Locations

Method one:

Direct reference pm2 official:
Log configuration


$ pm2 start echo.js --merge-logs --log-date-format="YYYY-MM-DD HH:mm Z"


--merge-logs                 do not postfix log file with process id
--log-date-format <format>   prefix logs with formated timestamp
-l --log [path]              specify entire log file (error and out are both included)
-o --output <path>           specify out log file
-e --error <path>            specify error log file

JSON way

  "script"          : "echo.js",
  "error_file"      : "err.log",
  "out_file"        : "out.log",
  "merge_logs"      : true,
  "log_date_format" : "YYYY-MM-DD HH:mm Z"

Combine out and err logs
To combine all logs into the same file set the same value for error_file, out_file or use an additional log_file.
For example, this keeps out and err separated but adds a combined file:

  "log_file": "combined.outerr.log",
  "out_file": "out.log",
  "err_file": "err.log"

Or if you want out and err combined without any other file, just use the same log file:

  "out_file": "combined.log",
  "err_file": "combined.log"

Note that relatives logs paths will usually be written in the PM2_HOME (~/.pm2/logs).
Method 2:

Modify ~/. Pm2 directory conf.js


 * Overidde PM2 configuration

var p    = require('path');

module.exports = function(DEFAULT_HOME) {

    return false;


  var pm2_conf = {
    PM2_HOME                 : PM2_HOME,

    PM2_LOG_FILE_PATH        : p.join(PM2_HOME, 'pm2.log'),
    PM2_PID_FILE_PATH        : p.join(PM2_HOME, ''),

    DEFAULT_PID_PATH         : p.join(PM2_HOME, 'pids'),
    //For example, changing the default location of pm2 logs. 
    DEFAULT_LOG_PATH         : '/data/pm2logs',
    DUMP_FILE_PATH           : p.join(PM2_HOME, 'dump.pm2'),

    DAEMON_RPC_PORT          : p.join(PM2_HOME, 'rpc.sock'),
    DAEMON_PUB_PORT          : p.join(PM2_HOME, 'pub.sock'),
    INTERACTOR_RPC_PORT      : p.join(PM2_HOME, 'interactor.sock'),

    GRACEFUL_TIMEOUT         : parseInt(process.env.PM2_GRACEFUL_TIMEOUT) || 8000,

    CONCURRENT_ACTIONS       : parseInt(process.env.PM2_CONCURRENT_ACTIONS) || 1,

    DEBUG                    : process.env.PM2_DEBUG || false,
    WEB_INTERFACE            : parseInt(process.env.PM2_API_PORT)  || 9615,
    MODIFY_REQUIRE           : process.env.PM2_MODIFY_REQUIRE || false,

    PM2_LOG_DATE_FORMAT      : process.env.PM2_LOG_DATE_FORMAT !== undefined ?process.env.PM2_LOG_DATE_FORMAT : 'YYYY-MM-DD HH:mm:ss',

    INTERACTOR_LOG_FILE_PATH : p.join(PM2_HOME, 'agent.log'),
    INTERACTOR_PID_PATH      : p.join(PM2_HOME, ''),
    INTERACTION_CONF         : p.join(PM2_HOME, 'agent.json5')

  return pm2_conf || null;

execute pm2 kill to kill the pm2 and then execute pm2 start your configuration to make the change take effect.

Read More: