Miss any of our Open RFC calls?Watch the recordings here! »

log4js-filters

0.1.1 • Public • Published

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: '******' }

Install

npm i log4js-filters

DownloadsWeekly Downloads

4

Version

0.1.1

License

Apache-2.0

Unpacked Size

7.77 kB

Total Files

7

Last publish

Collaborators

  • avatar