-
Notifications
You must be signed in to change notification settings - Fork 2.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Logs not working when app is ran in cluster mode #3215
Comments
Could you make a little example that replicate the problem ? Also which log framework are you using ? |
Sure @vmarchaud! To simplify things I created a project with the following files: package.json
index.jsconst express = require('express');
const log4js = require('log4js');
const app = express();
var logger = log4js.getLogger();
logger.level = 'debug';
app.get('/', (req, res) => {
logger.debug('Running default endpoint');
res.send('Hello World!');
});
app.listen(3000, ()=>{
logger.debug('App started on port 3000!');
}) pm2-cluster.ymlapps:
- script : index.js
instances : max
exec_mode : cluster pm2-fork.ymlapps:
- script : index.js
instances : 1
exec_mode : fork Output running pm2 with
|
The difference between cluster and fork is that with the cluster we need to override the few methods to redirect the logs, see these lines. I suspect that log4js doesn't actually broadcast log to |
I am seeing the same problem. Log4js & pm2 & cluster. The log4js stdout appender appears to be calling From what I can tell:
|
Same problem. Morgan and pm2 cluster. works fine in fork |
Looks like it does not enter in this method: https://github.com/Unitech/pm2/blob/master/lib/ProcessContainer.js#L200 |
log4js.configure({
appenders: { out: { type: 'stdout'}},
categories: { default: { appenders: ['out'], level: 'info'}},
disableClustering: true
}) |
I was having the same problem in both scenarios (cluster and fork) and the root cause was a zombie pm2 process ("PM2 v3.2.1: God Daemon"). I just killed it and now everything is working fine.
|
All logs are being written to pm2.log |
Can I know, when this is going to be fixed? |
@praveenax when someone will do PR, go ahead :) |
There is lot of unclear discussions regarding pm2 cluster with log4js. As for my current investigation it seems that the pm2-intercom is not needed. When using new version of log4js (5.2.2) the only required settings are:
I have tested by running 6 pm2 cluster nodes and ran 30 parallel jmeter workers to check whether any of the logs get lost. By comparing with the pm2 log (this is assumed to be cluster safe), I can see the log entries are identical. Here the complete test app:
|
We are experiencing the same issue. |
any plans to fix this issue? |
I'm experiencing the same problem. PM2: 4.5.6 It seems like the environment variables/config settings are not being used. Instead of writing to the specified log locations the logs are being written to When running the command The same thing for |
@brayden-bcgsc do you have a workaround for this? |
I'm using pm2 for an in-house app where scalability is not a huge concern at the moment, so I personally just swapped back to forked mode for the time being. I HAVE NOT TESTED THIS |
it looks like it still hasn't been solved as I'm having the same issue, is logs4j included by default with pm2 ? |
I have the same issue, I'm running yarn start and the logs don't show if I set cluster mode. Works fine on fork mode. |
Having the same issue when running in cluster mode. Any workaround for this? |
+1 just got experience with this |
Has this issue been resolved? |
Long story short Details and tests
PM2 config - test.json
Output of
So all good, now i just remove the
Which is wrong, the debug should be logged regardless.
|
Hi, I have an app that generates logs of different types such as DEBUG, WARN, ERROR, etc.
For some reason, when the app is ran in
exec_mode=cluster
none of the logs show up in the log files.This works as expected however when I run the app in
fork
mode.I tried setting
instances
frommax
to1
but did not work.Also, I had installed
pm2-syslog
and although it should be related, I stopped it.Any suggestions and/or workaround to solve this?
Thanks in advance!
h3. pm2 report
The text was updated successfully, but these errors were encountered: