3.2. Debug logging
Debug logging is a way to add detailed information to the application log when debugging. This allows you to:
- Keep minimal logging output during normal operation of the application for improved readability and reduced disk space usage.
- View detailed information about the inner workings of the application when resolving issues.
3.2.1. Add debug logging 링크 복사링크가 클립보드에 복사되었습니다!
This example uses the debug package, but there are also other packages available that can handle debug logging.
Prerequisites
- You have an application that you want to debug.
Procedure
Add the
debuglogging definition.const debug = require('debug')('myexample');Add debug statements.
app.use('/api/greeting', (request, response) => { const name = request.query ? request.query.name : undefined; //log name in debugging debug('name: '+name); response.send({content: `Hello, ${name || 'World'}`}); });Add the debug module to
package.json.... "dependencies": { "debug": "^3.1.0" }Depending on your application, this module may already be included. For example, when using the express generator to create your application, the
debugmodule is already added topackage.json.Install the application dependencies.
$ npm install