Search code examples
javascriptnode.jslog4javascriptlog4js-node

Log4js: logs depend on NODE_ENV


How can I make logs (INFO, ERROR) dependent on set NODE_ENV?

I mean, for example, if NODE_ENV=development, I write only ERROR logs. With NODE_ENV=production, there has to be only INFO.

How should I modify appenders to perform this?

Thanks for your help.


Solution

  • I have found more appropriate (for me) solution of this problem. Just configure categories in levels in this way:

    ...
          "levels": {
            "[all]": "INFO",
            "console": (env == "production" ? "ERROR" :"INFO")
          },
    ...
    

    I needed to think a little before rushing to stackoverflow :)