@dfcamposs/simple-json-logger-test
TypeScript icon, indicating that this package has built-in type declarations

4.1.1 • Public • Published

@vizir/simple-json-logger

A fast, simple and opinionated json logger to stdout.

npm version Node.js CI

Motivation

This library is designed to be an easy and fast way to log json messages to stdout.

If you want a more advanced solution, we recommend to you use winston.

Installation

$ npm install @vizir/simple-json-logger

Usage

NodeJS Sample with Javascript

const { Logger } = require("@vizir/simple-json-logger");

const logger = new Logger({
  app: "ConsoleApplication",
  requestId: "3a7d3223-e96f-47da-b3bb-73f609b9f55d",
});
logger.debug("debug message", { extraInfo: 123 });
logger.info("info message", { extraInfo: "abc" });
logger.warn("warn message", { moreInfo: "abc123" });
logger.error("error message", { otherInfo: "qwerty" });

Security Filtering

By default, the logger will filter some sensitive values from logs output. They will verify if an object key, contain some of the following words: (The validation is case insensitive)

  • Authorization
  • Password
  • Secret
  • Token
  • Key

You can add or remove the default blacklist, using the includeBlackList or excludeBlackList attribute into options, as following:

const logger = new Logger(
  {
    app: "ConsoleApplication",
    requestId: "3a7d3223-e96f-47da-b3bb-73f609b9f55d",
  },
  {
    includeBlackList: ["myPasswordField"],
    excludeBlackList: ["accessToken"],
  }
);
logger.error("error message", { myPasswordField: "qwerty" });

The output of the following command are:

{
  "app": "ConsoleApplication",
  "requestId": "3a7d3223-e96f-47da-b3bb-73f609b9f55d",
  "level": "error",
  "datetime": "2020-05-20T00:20:10.432Z",
  "message": "origin: error message",
  "myPasswordField": "*sensitive*"
}

Support

Tested in Node.js 10-12.

License

The MIT License (MIT)

Package Sidebar

Install

npm i @dfcamposs/simple-json-logger-test

Weekly Downloads

0

Version

4.1.1

License

MIT

Unpacked Size

17 kB

Total Files

15

Last publish

Collaborators

  • dfcamposs