简体   繁体   中英

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.

Looks like you are using a log suffix for your app. See the pm2 documentation here .

You can disable automatic ID suffixs on logs (eg app-name-ID.log ) by passing enabling the option merge_logs: true

So, your env file should look 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,
        merge_logs: true
    }
  ]
}

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM