Search code examples
javascriptloggingpm2

PM2 - How can i remove the identifier from the log file name


Im trying to remove the service identifier from the log file name.

Example:

My ecosystem.config.js looks like this:

module.exports = {
  apps : [
    {
        name: "My Service",
        script: "./app.js",
        watch: true,
        max_memory_restart: "150M",
        error: "/var/log/pm2/my-service.log",
        out: "/var/log/pm2/my-service.log",
        max_restarts: 10
    }
  ]
}

Then, i expect a log file named: /var/log/pm2/my-service.log.

But this is what it generates: /var/log/pm2/my-service-4.log.

I'm using pm2 version 3.5.0, I've just upgraded it from version 2.10.4

Node version: v8.16.0

UPDATE 1:

I've also tried using different parameters like merge_logs, here's an example of that version:

module.exports = {
  apps : [
    {
        name: "My Service",
        script: "./app.js",
        watch: true,
        max_memory_restart: "150M",
        error: "/var/log/pm2/my-service.log",
        out: "/var/log/pm2/my-service.log",
        max_restarts: 10,
        merge_logs: true
    }
  ]
}

UPDATE 2:

It seems like pm2 it's completely ignoring what i set in the error and output options. I've tried changing those options to error_file and out_file and then reloading the logs with pm2 reloadLogs but didn't work.


Solution

  • I've found the solution for this.

    It looks like pm2 is caching the ecosystem file, and it completely ignores the changes on the file once you start it.

    For making pm2 reload all the config again, you have to remove all the services and start them again.

    Here's what i did:

    pm2 delete all
    pm2 startOrRestart ecosystem.config.js
    

    After doing this, it reloaded the config and it started writing to the correct files.