The pino-debug module passes debug messages through pino so that log output is in newline-delimited JSON (a common logging format which offers a good compromise between machine and human readability).
Due to the performant techniques used by pino, using pino-debug leads to a performance increase in log writing (and therefore leaves more room for other in-process activities such as serving requests) even though there's more output per log message!
Let's copy our app folder to logging-app and install pino-debug:
$ cp -fr app logging-app
$ npm install --save pino-debug
We'll add two npm scripts, one for development and one for production. Let's edit package.json like so:
{
"name": "app",
"version": "1.0.0",
"description": "",
"main": "index.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"dev": "node index.js",
"prod": "node -r pino-debug index.js"
},
"keywords": [],
"author": "",
"license": "ISC",
"dependencies": {
"express": "^4.15.0",
"pino-debug": "^1.0.3",
"stylus": "^0.54.5"
}
}
Now we run the following:
$ DEBUG=* npm run --silent prod
We should see the express logs in JSON form, where the msg field contains the log contents and the ns field contains the relevant debug message. Additionally, pino adds a few other useful fields, such as time, pid, hostname, level (the log level defaults to 20, which is debug level), and v (the log format version):
Debug namespace to log level mapping
See the
pino-debug readme at
http://npm.im/pino-debug for mapping namespaces to custom log levels.