0.1.1 • Published 5 years ago

log4js-filters v0.1.1

Weekly downloads
2
License
Apache-2.0
Repository
github
Last release
5 years ago

log4js-filters Build Status codecov

NPM

This is a log filtering plugin for log4js-node. It checks log object keys against pre-configured words or regex and hide the log content accordingly. See below for an example.

NOTE: Logs have to be of object form. Strings won't get filtered.

Installation

npm install --save log4js-filters

Usage

// Example to filter password and any email in logs.

const { log4js, layout } = require('log4js-filters');

// Add a filter to catch "password" key
layout.exact = ['password'];

// Add a filter to catch any key containing "email"
layout.regex = ['email'];

log4js.configure({
  appenders: {
    stdout: {
      type: 'stdout',
      layout
    },
  },
  categories: {
    default: { appenders: ['stdout'], level: 'debug'},
  },
});

const logger = log4js.getLogger();
logger.debug({
  username: 'test', password: 'hide-me', userEmail: 'hide-me@example.com',
});

Output:

[DEBUG] default - { username: 'test', password: '******', userEmail: '******' }