
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
node-json-logger
Advanced tools
Simply, output logs to STDOUT in JSON
npm i node-json-logger
const Logger = require('node-json-logger');
const logger = new Logger();
logger.info();
logger.info('message');
logger.info('message','message','message');
logger.info({ data: 'data' });
logger.info({ data1: 'data' }, { data2: 'data' });
logger.info('message', { data1: 'data' }, 'message', { data2: 'data' }, 'message');
Outputs:
{"timestamp":"2001-03-14T01:00:00.000Z","level":"info"}
{"timestamp":"2001-03-14T01:00:00.000Z","level":"info","message":"message"}
{"timestamp":"2001-03-14T01:00:00.000Z","level":"info","message":"message","message1":"message","message2":"message"}
{"timestamp":"2001-03-14T01:00:00.000Z","level":"info","data":"data"}
{"timestamp":"2001-03-14T01:00:00.000Z","level":"info","data1":"data","data2":"data"}
{"timestamp":"2001-03-14T01:00:00.000Z","level":"info","message":"message","data1":"data","message1":"message","data2":"data","message2":"message"}
logger.xxx(message?, ...)
Note:
Arguments:
Specify output level. (optional, default is debug)
const Logger = require('node-json-logger');
const logger = new Logger({ level: 'error'});
logger.trace('message');
logger.debug('message');
logger.info('message');
logger.warn('message');
logger.error('message');
logger.fatal('message');
Output:
{"timestamp":"2001-03-14T01:00:00.000Z","level":"error","message":"message"}
{"timestamp":"2001-03-14T01:00:00.000Z","level":"fatal","message":"message"}
Level and output:
| trace | debug | info | warn | error | fatal | |
|---|---|---|---|---|---|---|
{ level: 'trace' } | O | O | O | O | O | O |
{ level: 'debug' } | - | O | O | O | O | O |
{ level: 'info' } | - | - | O | O | O | O |
{ level: 'warn' } | - | - | - | O | O | O |
{ level: 'error' } | - | - | - | - | O | O |
{ level: 'fatal' } | - | - | - | - | - | O |
{ level: 'none' } | - | - | - | - | - | - |
Specify the name of the logger. Useful when logging from different files.
const Logger = require('node-json-logger');
const logger = new Logger({ loggerName: 'server/index.js' });
logger.info('message');
Output:
{"timestamp":"2001-03-14T01:00:00.000Z","level":"info","loggerName":"server/index.js","message":"message"}
Specify enable or disable timestamp. (optional, default is true)
const Logger = require('node-json-logger');
const logger = new Logger({ timestamp: false });
logger.info('message');
Output with disabled timestamp:
{"level":"info","message":"message"}
Specify locale timezone. (optional, default is UTC)
const Logger = require('node-json-logger');
const logger = new Logger({timezone: 'America/Sao_Paulo'});
logger.info('message');
Output with specific timezone:
{"timestamp":"2018-10-25T15:32:43.318Z","level":"info","message":"message"}
Same output with default timezone (UTC):
{"timestamp":"2018-10-25T18:32:43.318Z","level":"info","message":"message"}
Click here to see the list with all available timezones.
MIT
Copyright ©2018 Hiroaki SHIBUKI a.k.a. hidori
FAQs
Simply, output logs to STDOUT in JSON
The npm package node-json-logger receives a total of 2,004 weekly downloads. As such, node-json-logger popularity was classified as popular.
We found that node-json-logger demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.