I'm new to node - js Console Delete log statement? Or is it OK to leave them?
What is the correct way to handle the local code filled with debugging statements, without losing the statement, but pushing them for production.
I develop locally
Thank you for your expertise.
I have a log assistant file. I then use the debug mode field in my config.json or environment variable, and I use nconf npm to read from it.
Log down below. An example of a coffee file
## # * Application for console logging nconf = require ('nconf') nconf.argv () .env (). File file: "./config.json" # Log # log information on console: # code - deleted, error, warning, info # message - log message to display # data - optional data info # Returns: nothing module.exports.log = (code, message, data) - & gt; If nconf.get ('DEBUG_MODE') == 'true' || Nconf.get ('DEBUG_MODE') == if the data is correct? # If the data is an object, then type data == 'object' data = JSON.stringify (data) console.log code.toUpperCase () + ':' + message console.log code.toUpperCase () for output To save it + ':' + '(continued)' + Data other console.log code. To follow up () + ':' + message " Then I want to log in any file, I just include this file and use console.log everywhere Instead log in for it.
sample.coffee
logger = require ('../log') module.exports .getEvent = (eventDb) - & gt; Logger.log 'debug', '/ server / adapters / event / getEvent name', eventDb logger allows for a severity code, message, and optional data that will appear in Terminal and if you are not in debug mode, then it will not do anything.
No comments:
Post a Comment