Debugging protocols with React

I would like to:

  • embed debugging reports in my code, which I want to turn on and off during development; and
  • then these statements are completely excluded in the production process.

In order to delete logs for production, I saw that the React project itself uses this idiom:

if ("production" !== process.env.NODE_ENV) {
    // warn or log or whatever
}

By compiling the modules with process.env.NODE_ENVinstalled on "production", and then launching the bundle through a dead code ejector, such as UglifyJS, the logs will be excluded as inaccessible.

This is good, but are there more flexible solutions? I think something like a debug()Node module , or indeed some more powerful ones, such as the Java Registration API.

I am wondering why I do not find a module that combines the approach ("production" !== process.env.NODE_ENV)with debug().

+4
2
var debug = function(msg) {
    if ("production" !== process.env.NODE_ENV) console.log(msg);
}
module.exports = debug;

:

var debug = require("debug");
debug("some logs");

, ;). , JS ( , , ).

+6

Java , log4javascript.

http://log4javascript.org/

, ...

enter image description here

0

Source: https://habr.com/ru/post/1609881/


All Articles