Skip to content
This repository has been archived by the owner on Feb 18, 2024. It is now read-only.

log4js can't get output. #894

Closed
lubo08 opened this issue May 21, 2018 · 7 comments
Closed

log4js can't get output. #894

lubo08 opened this issue May 21, 2018 · 7 comments

Comments

@lubo08
Copy link

lubo08 commented May 21, 2018

I'm using just plain new neutrino node js project, I try ale with web project, When I use log4js I'm not able get to run logging to console even to file. Can somebody help with example how implement log4js into neutrino project?

@eliperelman
Copy link
Member

@lubo08 Could you share a sample of your project so we can see if Neutrino is the one interfering here?

@lubo08
Copy link
Author

lubo08 commented May 25, 2018

I just follow instruction how create neutrino project and then put log4js as describe on their page. I discover that if I set this parameter in log4js config it start working "disableClustering": true .

@edmorley
Copy link
Member

Hi! Unfortunately there are quite a few details missing from this bug report - that were asked in the issue template that was deleted (it's worth noting that some open source projects immediately close any issues where the template was removed, so I'd generally recommend not deleting it).

For example:

  • what neutrino commands are you running? (eg start or build)
  • what does your .neutrinorc.js contain?
  • are you using the log4js or log4js-node package?
  • what was the log4js(-node) configuration?

@lubo08
Copy link
Author

lubo08 commented May 25, 2018

Hi
So my steps was:

  1. create new neutrino project yarn create @neutrinojs/project nodes
  2. now I choose node project
  3. then put into index.js , log4js-node project.
    var log4js = require('log4js'); var logger = log4js.getLogger(); logger.level = 'debug'; logger.debug("Some debug messages");
  4. Now run it wit yarn start but logs are missing.
  5. so create log4js configuration
    log4js.configure({ "disableClustering": true, appenders: { app: { type: 'console' } }, categories: { default: { appenders: ['app'], level: 'debug' } } });
    Now log start working. You do not need define console appender as it is by default set. But I try it but not help just after set disableClustering to true it start working.

@edmorley
Copy link
Member

Thank you for the extra info.

When using the node preset, neutrino start (which is what is run by yarn start) uses start-server-webpack-plugin to automatically run the generated entrypoint, once the webpack build completes.

The current version of start-server-webpack-plugin uses the node cluster API to start the server:
https://github.com/ericclemmons/start-server-webpack-plugin/blob/v2.2.5/src/StartServerPlugin.js#L138-L144

From reading log4js-node/log4js-node#265 and https://log4js-node.github.io/log4js-node/faq.html it sounds like log4js-node v2.x changed the way logs are handled when run with cluster, such that all the logs are sent to the master process. In this case, the master process will be the webpack build process/neutrino, rather than your app, so this new log4js-node behaviour is actually not desirable in this case.

If I try with yarn build instead, then the logging works even without disableClustering: true, which confirms the theory that it's due to unfortunate interaction between log4js-node and start-server-webpack-plugin.

It looks like the next major version of start-server-webpack-plugin will switch from cluster to childprocess.fork(), which may mean the log4js-node disableClustering: true option is no longer required:
ericclemmons/start-server-webpack-plugin#19

I also tried with Neutrino master, in case the switch from webpack APIs to the webpack CLI (#852) made a difference - but it does not. As such, it doesn't seem like there is anything Neutrino 8 is doing wrong with the usage of the webpack API/logging - and that start-server-webpack-plugin's need for disabling clustering is something that perhaps just needs to go on the log4js-node FAQ page?

@lubo08
Copy link
Author

lubo08 commented May 25, 2018

Thank you for explanation. You are true. At the beginning I was so confused as there was no error no logs, nothing. So I have to run log4js in debug mode to discover this clustering behaviour. But hope this could help also somebody else :). So this issue could be closed as solved.

@edmorley
Copy link
Member

It must have been a pain to track down! Glad you have it working now - and agree this will give something for people to search against (there is nothing currently in the log4js or start-server-webpack-plugin issue trackers, nor on Stack Overflow).

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Development

No branches or pull requests

3 participants